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 n, k 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取模余数相等的有多少个。。
ac代码:
 1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <algorithm>
5 using namespace std;
6 const int maxn = 1e5+5;
7 int nu[maxn];
8 int cnt[maxn];
9 int main() {
10 ios::sync_with_stdio(false);
11 int n,k,m,i;
12 cin>>n>>k>>m;
13 for(i=1;i<=n;++i) {
14 cin>>nu[i];
15 }
16 int ans=-1;
17 for(i=1;i<=n;++i) {
18 int u=nu[i]%m;
19 ++cnt[u];
20 if(cnt[u]==k) {
21 ans=u;
22 break;
23 }
24 }
25 if(ans==-1) cout<<"No"<<endl;
26 else {
27 cout<<"Yes"<<endl;
28 for(int i=1;i<=n;++i) {
29 if(nu[i]%m==ans) {
30 --k;
31 cout<<nu[i]<<" ";
32 }
33 if(k==0) break;
34 }
35 }
36 return 0;
37 }

codeforces 876B的更多相关文章

  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 - 876B H - 差异的可分割性

    现在有n个整数,在这n个数中找出k个数,保证这k个数中任意两个数差的绝对值可以被m整除. Input第一行输入三个整数n,k,m(2<=k<=n<=100000,1<=m< ...

  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. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. 对于Spring MVC 拦截器的一些了解

    Spring MVC 拦截器的执行顺序 应用场景 假设请求 localhost:8080/ 则要求直接重定向到 localhost:8080/login ; 定义拦截器顺序 permission lo ...

  2. Go 语言编译过程

    走进Golang之编译器原理_大愚Talk-CSDN博客 https://blog.csdn.net/hel12he/article/details/103061921 go编译器 - 知乎 http ...

  3. 回滚原理 Since database connections are thread-local, this is thread-safe.

    mysql django 实践: django @transaction.atomic 机制分析  1.数据库清空表Tab 2.请求django-view        @transaction.at ...

  4. 前序遍历 排序 二叉搜索树 递归函数的数学定义 return 递归函数不能定义为内联函数 f(x0)由f(f(x0))决定

    遍历二叉树   traversing binary tree 线索二叉树 threaded binary tree 线索链表 线索化 1. 二叉树3个基本单元组成:根节点.左子树.右子树 以L.D.R ...

  5. css知识补充

    盒子模型的介绍: 在网页中基本上都会显示一些方方正正的盒子,这种盒子就被我们称为盒模型 盒子模型的五个属性: width,height,border(边框),padding(内边距),margin(外 ...

  6. 正则r的作用

    >>> mm = "c:\\a\\b\\c" >>> mm 'c:\\a\\b\\c' >>> print(mm) c:\a\ ...

  7. CODEVS 2542单词__fail树

    2542 单词 2013年省队选拔赛天津市队选拔赛  时间限制: 2 s  空间限制: 256000 KB  题目等级 : 大师 Master     题目描述 Description 小张最近在忙毕 ...

  8. GJ项目技术代码相关总结

    第一次实习公司的GJ项目快要结束,自己总结了一些工作中的代码,留到记录学习. 根据下拉条件,进行查询,展示出不同的表单选项:并在鼠标进入到指定区域时显示部分内容,鼠标移出内容区域时,隐藏内容. 焦点移 ...

  9. 小白搭建WNMP详细教程---NGINX、MYSQL、PHP的整合配置

    我自定义安装后的目录结构如下: 安装在D盘的WNMP下,其中WWW是网站的目录.ZIPS是放压缩包文件. 一.配置环境变量 在桌面右击我的电脑,选择属性,出现窗口后,按下图所示操作: 点击编辑后,会出 ...

  10. Jenkins(8)构建触发器之定时构建和轮询 SCM

    前言 跑自动化用例每次用手工点击jenkins出发自动化用例太麻烦了,我们希望能每天固定时间跑,这样就不用管了,坐等收测试报告结果就行. jenkins的定时任务是用的crontab语法 定时构建语法 ...