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

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 31 8 4
output
Yes1 4
input
3 3 31 8 4
output
No
input
4 3 52 7 7 7
output
Yes2 7 7 思路：　　如果(a-b)%m==0 ==> a%m = b%m.　　所以判断求出每个数膜m余多少就好了。
 1 #include <bits/stdc++.h>
2
3 using namespace std;
4
5 #define MP make_pair
6 #define PB push_back
7 typedef long long LL;
8 typedef pair<int,int> PII;
9 const double eps=1e-8;
10 const double pi=acos(-1.0);
11 const int K=1e6+7;
12 const int mod=1e9+7;
13
14 int n,m,k,a[K],cnt[K];
15
16 int main(void)
17 {
18     cin>>n>>k>>m;
19     for(int i=1,x;i<=n;i++)
20         scanf("%d",a+i),cnt[a[i]%m]++;
21     for(int i=0;i<m;i++)
22     if(cnt[i]>=k)
23     {
24         printf("Yes\n");
25         for(int j=1,num=0;j<=n;j++)
26         if(a[j]%m==i)
27         {
28             printf("%d ",a[j]);
29             if(++num==k)
30                 return 0;
31         }
32     }
33     printf("No\n");
34     return 0;
35 }

posted @ 2017-10-17 10:55  weeping  阅读(208)  评论(0编辑  收藏  举报