1213D1.md (1458B)
1 Source: https://codeforces.com/problemset/problem/1213/D1 2 3 D1. Equalizing by Division (easy version) 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 The only difference between easy and hard versions is the number of elements in the array. 22 23 You are given an array $a$ consisting of $n$ integers. In one move you can choose any $a_i$ and divide it by $2$ rounding down (in other words, in one move you can set $a_i := \lfloor\frac{a_i}{2}\rfloor$). 24 25 You can perform such an operation any (possibly, zero) number of times with any $a_i$. 26 27 Your task is to calculate the minimum possible number of operations required to obtain at least $k$ equal numbers in the array. 28 29 Don't forget that it is possible to have $a_i = 0$ after some operations, thus the answer always exists. 30 31 Input 32 33 The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 50$) — the number of elements in the array and the number of equal numbers required. 34 35 The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. 36 37 Output 38 39 Print one integer — the minimum possible number of operations required to obtain at least $k$ equal numbers in the array. 40 41 Examples 42 43 Input 44 45 ``` 46 5 3 47 1 2 2 4 5 48 ``` 49 50 Output 51 52 ``` 53 1 54 ``` 55 56 Input 57 58 ``` 59 5 3 60 1 2 3 4 5 61 ``` 62 63 Output 64 65 ``` 66 2 67 ``` 68 69 Input 70 71 ``` 72 5 3 73 1 2 3 3 3 74 ``` 75 76 Output 77 78 ``` 79 0 80 ```