Henry writes Chinese essays every day to prepare for the upcoming HKDSE examination. He has written $N$ essays so far, the $i$-th essay consists of $A_i$ characters.
Now, Henry wants to post $K$ of his $N$ essays to the popular Android app Fascinating Compositions. Due to aesthetic considerations, Henry wants the $K$ essays he post to have the same number of characters. Therefore, Henry will edit his essays to meet this requirement.
In one operation, Henry can add one character to any essay. What is the minimum number of operations for Henry to meet the requirement?
Input
The first line of input contains two integers $N, K$.
The second line of input contains $N$ integers $A_1, A_2, \cdots, A_N$.
Output
Output an integer: the minimum number of operations for Henry to have $K$ essays with the same number of characters.
Constraints
For all subtasks, $1 \le K \le N \le 10^5, 1 \le A_i \le 10^9$
Subtask 1 (30%): $1 \le N \le 2000$
Subtask 2 (70%): No additional constraints
Sample Test Cases
Input | Output | |
---|---|---|
5 3 500 600 900 200 400 |
300 | |
Henry can add 200 characters to the essay with 400 characters and 100 characters to the essay with 500 characters. Then there are 3 essays with 600 characters. |
Scoring: Per Subtask
Authored by s16f22
Appeared in 2022 Wah Yan Interschool Olympiad in Informatics 🤯🥷⚡🧠🏆