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. 【Android】报错 Please ensure Hyper-V is disabled in Windows Features, or refer to the Intel HAXM 的解决方案

    参考文章 实测华为锐龙本(adm yes)安装Android avd虚拟机教程 环境 Android Studio 3.6; Windows 1909; AMD Ryzen 4800U with Ra ...

  2. 【Android初级】使用setContentView实现页面的转换效果(附源码)

    一提到Android中页面的切换,你是不是只想到了startActivity启动另一个Activity? 其实在Android中,可以直接利用setContentView达到类似页面转换效果的!实现思 ...

  3. h3c交换机配置ssh密码验证登录方式

    一.背景: 1.由于PC机串口不支持热插拔,请不要在交换机带电的情况下,将串口插入或者拔出PC机.当连接PC和交换机时,请先安装配置电缆的DB-9端到PC机,再连接RJ-45到交换机:在拆下时,先拔出 ...

  4. 我们都可以把它放 Sidecar 容器中,这样微服务具备了 Super power,一种超能力

    云原生时代,微服务如何演进? 原创 李响 阿里技术 2020-08-28   https://mp.weixin.qq.com/s/KQG2U8_aotDL4YFB8ee6Zw 一  微服务架构与云原 ...

  5. 大白话入门 Spring Cloud

    首先我给大家看一张图,如果大家对这张图有些地方不太理解的话,我希望你们看完我这篇文章会恍然大悟. 什么是Spring cloud 构建分布式系统不需要复杂和容易出错.Spring Cloud 为最常见 ...

  6. 静电、浪涌与TVS

    ESD和浪涌问题往往是基带工程师最头疼的问题,因为测试标准严苛,问题神出鬼没.特别是ESD问题,没有解决问题的标准路径,只能靠反复地构思方案并验证.想要尽量避免以上问题,就必须选择合适的防护器件,设计 ...

  7. 某cms最新版前台RCE漏洞(无需任何权限)2020-03-15

    漏洞文件:application/common/controller/Base.php 中的 getAddonTemplate 方法: 错误的使用了public,导致我们可以直接外部访问. 然后使用了 ...

  8. 学习SpringBoot,整合全网各种优秀资源,SpringBoot基础,中间件,优质项目,博客资源等,仅供个人学习SpringBoot使用

    学习SpringBoot,整合全网各种优秀资源,SpringBoot基础,中间件,优质项目,博客资源等,仅供个人学习SpringBoot使用 一.SpringBoot系列教程 二.SpringBoot ...

  9. spark SQL (二) 聚合

    聚合内置功能DataFrames提供共同聚合,例如count(),countDistinct(),avg(),max(),min(),等.虽然这些功能是专为DataFrames,spark SQL还拥 ...

  10. Effective Java读书笔记--类和接口

    1.使类和成员的可访问性最小化不指定访问级别,就是包私有.protected = 包私有 + 子类一般private不会被访问到,如果实现了Serializable,可能会泄露.反射.final集合或 ...