codeforces-scrape

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

723C.md (2461B)


      1 Source: https://codeforces.com/problemset/problem/723/C
      2 
      3 C. Polycarp at the Radio
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence *a*1, *a*2, ..., *a**n*, where *a**i* is a band, which performs the *i*-th song. Polycarp likes bands with the numbers from 1 to *m*, but he doesn't really like others.
     22 
     23 We define as *b**j* the number of songs the group *j* is going to perform tomorrow. Polycarp wants to change the playlist in such a way that the minimum among the numbers *b*1, *b*2, ..., *b**m* will be as large as possible.
     24 
     25 Find this maximum possible value of the minimum among the *b**j* (1 ≤ *j* ≤ *m*), and the minimum number of changes in the playlist Polycarp needs to make to achieve it. One change in the playlist is a replacement of the performer of the *i*-th song with any other group.
     26 
     27 Input
     28 
     29 The first line of the input contains two integers *n* and *m* (1 ≤ *m* ≤ *n* ≤ 2000).
     30 
     31 The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 109), where *a**i* is the performer of the *i*-th song.
     32 
     33 Output
     34 
     35 In the first line print two integers: the maximum possible value of the minimum among the *b**j* (1 ≤ *j* ≤ *m*), where *b**j* is the number of songs in the changed playlist performed by the *j*-th band, and the minimum number of changes in the playlist Polycarp needs to make.
     36 
     37 In the second line print the changed playlist.
     38 
     39 If there are multiple answers, print any of them.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 4 2  
     47 1 2 3 2
     48 ```
     49 
     50 Output
     51 
     52 ```
     53 2 1  
     54 1 2 1 2
     55 ```
     56 
     57   
     58   
     59   
     60 
     61 Input
     62 
     63 ```
     64 7 3  
     65 1 3 2 2 2 2 1
     66 ```
     67 
     68 Output
     69 
     70 ```
     71 2 1  
     72 1 3 3 2 2 2 1
     73 ```
     74 
     75   
     76   
     77   
     78 
     79 Input
     80 
     81 ```
     82 4 4  
     83 1000000000 100 7 1000000000
     84 ```
     85 
     86 Output
     87 
     88 ```
     89 1 4  
     90 1 2 3 4
     91 ```
     92 
     93 Note
     94 
     95 In the first sample, after Polycarp's changes the first band performs two songs (*b*1 = 2), and the second band also performs two songs (*b*2 = 2). Thus, the minimum of these values equals to 2. It is impossible to achieve a higher minimum value by any changes in the playlist.
     96 
     97 In the second sample, after Polycarp's changes the first band performs two songs (*b*1 = 2), the second band performs three songs (*b*2 = 3), and the third band also performs two songs (*b*3 = 2). Thus, the best minimum value is 2.