codeforces-scrape

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

1490F.md (1708B)


      1 Source: https://codeforces.com/problemset/problem/1490/F
      2 
      3 F. Equalize the Array
      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 was gifted an array $a$ of length $n$. Polycarp considers an array beautiful if there exists a number $C$, such that each number in the array occurs either zero or $C$ times. Polycarp wants to remove some elements from the array $a$ to make it beautiful.
     22 
     23 For example, if $n=6$ and $a = [1, 3, 2, 1, 4, 2]$, then the following options are possible to make the array $a$ array beautiful:
     24 
     25 * Polycarp removes elements at positions $2$ and $5$, array $a$ becomes equal to $[1, 2, 1, 2]$;
     26 * Polycarp removes elements at positions $1$ and $6$, array $a$ becomes equal to $[3, 2, 1, 4]$;
     27 * Polycarp removes elements at positions $1, 2$ and $6$, array $a$ becomes equal to $[2, 1, 4]$;
     28 
     29 Help Polycarp determine the minimum number of elements to remove from the array $a$ to make it beautiful.
     30 
     31 Input
     32 
     33 The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow.
     34 
     35 The first line of each test case consists of one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the array $a$.
     36 
     37 The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — array $a$.
     38 
     39 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
     40 
     41 Output
     42 
     43 For each test case, output one integer — the minimum number of elements that Polycarp has to remove from the array $a$ to make it beautiful.
     44 
     45 Example
     46 
     47 Input
     48 
     49 ```
     50 3
     51 6
     52 1 3 2 1 4 2
     53 4
     54 100 100 4 100
     55 8
     56 1 2 3 3 3 2 6 6
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 2
     63 1
     64 2
     65 ```