codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

876B.md (1557B)


      1 Source: https://codeforces.com/problemset/problem/876/B
      2 
      3 B. Divisiblity of Differences
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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.
     24 
     25 Input
     26 
     27 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.
     28 
     29 Second line contains *n* integers *a*1, *a*2, ..., *a**n* (0 ≤ *a**i* ≤ 109) — the numbers in the multiset.
     30 
     31 Output
     32 
     33 If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes).
     34 
     35 Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1, *b*2, ..., *b**k* — the selected numbers. If there are multiple possible solutions, print any of them.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 3 2 3  
     43 1 8 4
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 Yes  
     50 1 4
     51 ```
     52 
     53 Input
     54 
     55 ```
     56 3 3 3  
     57 1 8 4
     58 ```
     59 
     60 Output
     61 
     62 ```
     63 No
     64 ```
     65 
     66 Input
     67 
     68 ```
     69 4 3 5  
     70 2 7 7 7
     71 ```
     72 
     73 Output
     74 
     75 ```
     76 Yes  
     77 2 7 7
     78 ```