B. Divisiblity of Differences
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.

Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.

Input

First line contains three integers nk and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.

Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.

Output

If it is not possible to select k numbers in the desired way, output «No» (without the quotes).

Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.

Examples
input
3 2 3
1 8 4
output
Yes
1 4
input
3 3 3
1 8 4
output
No
input
4 3 5
2 7 7 7
output
Yes
2 7 7 每个数%m取相同的就行了;
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std; int n,k,m,a[],b[],c[]; int main(){
scanf("%d%d%d",&n,&k,&m);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
int j=-;
for(int i=;i<=n;i++){
b[i]=a[i]%m;
c[b[i]]++;
if(c[b[i]]>=k){
j=b[i];
break;
}
}
if(j==-){
printf("No");
return ;
}
printf("Yes\n");
int num=;
for(int i=;i<=n;i++)
if(b[i]==j){
num++;
printf("%d ",a[i]);
if(num==k) break;
}
}

Codeforces B. Divisiblity of Differences的更多相关文章

  1. Codeforces 876B Divisiblity of Differences:数学【任意两数之差为k的倍数】

    题目链接:http://codeforces.com/contest/876/problem/B 题意: 给你n个数a[i],让你找出一个大小为k的集合,使得集合中的数两两之差为m的倍数. 若有多解, ...

  2. CodeForces - 876B Divisiblity of Differences

    题意:给定n个数,从中选取k个数,使得任意两个数之差能被m整除,若能选出k个数,则输出,否则输出“No”. 分析: 1.若k个数之差都能被m整除,那么他们两两之间相差的是m的倍数,即他们对m取余的余数 ...

  3. codeforces #441 B Divisiblity of Differences【数学/hash】

    B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input ...

  4. Codeforces 876B:Divisiblity of Differences(数学)

    B. Divisiblity of Differences You are given a multiset of n integers. You should select exactly k of ...

  5. B. Divisiblity of Differences

    B. Divisiblity of Differencestime limit per test1 secondmemory limit per test512 megabytesinputstand ...

  6. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) B. Divisiblity of Differences

    http://codeforces.com/contest/876/problem/B 题意: 给出n个数,要求从里面选出k个数使得这k个数中任意两个的差能够被m整除,若不能则输出no. 思路: 差能 ...

  7. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)

    A. Trip For Meal 题目链接:http://codeforces.com/contest/876/problem/A 题目意思:现在三个点1,2,3,1-2的路程是a,1-3的路程是b, ...

  8. Codeforces Round #441 (Div. 2)【A、B、C、D】

    Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...

  9. Codeforces Round #441 (Div. 2)

    Codeforces Round #441 (Div. 2) A. Trip For Meal 题目描述:给出\(3\)个点,以及任意两个点之间的距离,求从\(1\)个点出发,再走\(n-1\)个点的 ...

随机推荐

  1. linux基础命令学习总结

    本附录([美]哈恩:<Unix&Linux大学教程>附录B,张杰良译,清华大学出版社,2010年)摘要描述了书中所涉及的143个Unix使命,并且按照命令的类别进行排列.在每个名称 ...

  2. [翻译]QT core wallet manual 狗狗币核心钱包使用教程

    译注:比特币没赶上可以玩狗狗币啊,水电厂包不起可以用CPU挖啊.为了顺应时代潮流,了解一下区(fa)块(heng)链(cai)和加密货币技术,准备从研究狗狗币开始.网上找了一圈没有看到很好的入门级教程 ...

  3. Java与算法之(3) - 斐波那契数列

    斐波那契数列问题:如果一对兔子每月能生1对小兔子,而每对小兔在它出生后的第三个月里,又能开始生1对小兔子,假定在不发生死亡的情况下,由一对初生的兔子开始,1年后能繁殖出多少对兔子? 首先手工计算来总结 ...

  4. 记一次python的一些参数

    isdigit把字符串转化为整数 用法 if xx.isdigit(): xx=int(xx) index创建一个小原组,用法print(a.index(b),b)从0开始

  5. GNS3的配置

    为了更好的了解协议我决定学习CCNA 安装好GNS3后我们打开 点击设置 先把iso解压,解压完成后倒入 保存结束 然后在输入idlepc get 设备名称 来计算idepc的值 idepc能让我们p ...

  6. Cnm%(个人模版)

    Cnm%: #include<stdio.h> #include<string.h> #include<vector> using namespace std; # ...

  7. C/C++中__builtin_popcount()的使用及原理

    __builtin_popcount()用于计算一个 32 位无符号整数有多少个位为1 Counting out the bits     可以很容易的判断一个数是不是2的幂次:清除最低的1位(见上面 ...

  8. 基于Windows环境下MyEclipse10快捷键总结

    ---------------------------------------------MyEclipse 快捷键1(CTRL)----------------------------------- ...

  9. Gym 100952B&&2015 HIAST Collegiate Programming Contest B. New Job【模拟】

    B. New Job time limit per test:1 second memory limit per test:64 megabytes input:standard input outp ...

  10. UESTC 1591 An easy problem A【线段树点更新裸题】

    An easy problem A Time Limit: 2000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others ...