B. Divisiblity of Differences

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

题意

给出n个数字,问能否从中挑选出k个数,使这k个数任意之间的差能被m整除。

思路

两个数相减能够被m整除,也就是说这两个数对m取模得到的结果是相同的

所以只要统计数组中的每个元素对m取模的结果的个数,判断是否大于k,如果没有大于k的,那么输出No

否则,找到出现次数最多的那个值(任意一个都可以,只要大于等于k),假设为mo,遍历数组,如果对m取模等于mo,输出,直到输出k个,停止

代码

 1 #include <bits/stdc++.h>
2 #define ll long long
3 #define ull unsigned long long
4 #define ms(a,b) memset(a,b,sizeof(a))
5 const int inf=0x3f3f3f3f;
6 const ll INF=0x3f3f3f3f3f3f3f3f;
7 const int maxn=1e6+10;
8 const int mod=1e9+7;
9 const int maxm=1e3+10;
10 using namespace std;
11 int a[maxn];
12 int vis[maxn];
13 bool cmp(int a,int b)
14 {
15 return a>b;
16 }
17 int main(int argc, char const *argv[])
18 {
19 #ifndef ONLINE_JUDGE
20 freopen("/home/wzy/in.txt", "r", stdin);
21 freopen("/home/wzy/out.txt", "w", stdout);
22 srand((unsigned int)time(NULL));
23 #endif
24 ios::sync_with_stdio(false);
25 cin.tie(0);
26 int n,m,k;
27 cin>>n>>k>>m;
28 int cnt=0;
29 int num;
30 int maxx=0;
31 for(int i=0;i<n;i++)
32 {
33 cin>>a[i];
34 if(!vis[a[i]%m])
35 cnt++;
36 vis[a[i]%m]++;
37 if(maxx<vis[a[i]%m])
38 maxx=vis[a[i]%m],num=a[i]%m;
39 }
40 if(maxx<k)
41 cout<<"No\n";
42 else
43 {
44 int res=0;
45 cout<<"Yes\n";
46 for(int i=0;i<n;i++)
47 {
48 if(a[i]%m==num)
49 {
50 res++;
51 cout<<a[i]<<" ";
52 }
53 if(res==k)
54 break;
55 }
56 cout<<"\n";
57 }
58 #ifndef ONLINE_JUDGE
59 cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
60 #endif
61 return 0;
62 }

最新文章

  1. java时间
  2. TCPIP、Http、Socket的协议~ 写得挺形象,赞
  3. 一个仿windows泡泡屏保的实现
  4. x01.Game.Main: 从零开始
  5. IE6-9中tbody的innerHTML不能赋值bug
  6. Oracle DBA需掌握的命令集锦(推荐)
  7. Qt一个project调用还有一个project的类成员变量
  8. [原]Unity3D深入浅出 - 新版动画系统(Mecanim)
  9. eayui 验证扩展
  10. java InputStream使用
  11. SQL注入的原理解说,挺好!
  12. C#第八天
  13. Git add和commit步骤分析
  14. Delphi引用C对象文件(转)
  15. 实现Windows数据绑定
  16. SQL Server中存储过程的创建命令
  17. php foreach跳出本次/当前循环与终止循环方法
  18. Java编程的逻辑 (89) - 正则表达式 (中)
  19. Windows驱动开发
  20. 动态产生select option列表

热门文章

  1. day34 前端基础之JavaScript
  2. Flume对接Kafka
  3. 在 Qualys SSL Labs SSL 测试中获得 A+ 评级的秘技 2021 版
  4. Android项目的settings.gradle和build.gradle
  5. Shell脚本字符串截取方法总结
  6. 转 android design library提供的TabLayout的用法
  7. archive后upload to app store时遇到app id不可用的问题
  8. 银行业评分卡制作——IV、WOE
  9. linux文件属性和系统信息
  10. 多个工作簿拆分(Excel代码集团)