#P15135. [SWERC 2025] Adjusting Drones
[SWERC 2025] Adjusting Drones
题目描述
You are managing a fleet of drones, each with an energy level . You are also given a positive integer , which represents the maximum number of drones allowed to share the same energy level.
To prevent overloads, the drones automatically perform energy balancing operations as follows. While there exists an energy level that appears strictly more than times, they execute the following steps:
- first, every drone whose energy has already appeared before (that is, there exists with ) is marked;
- then, for each marked drone, its energy is increased by 1 unit;
- then, the marks are removed.
The process stops once no energy level appears more than times. Determine how many energy balancing operations will be performed.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers () — the number of drones and the maximum allowed number of drones with the same energy level.
The second line of each test case contains integers () — the initial energy levels of the drones.
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, output a single line containing an integer: the number of energy balancing operations performed.
5
6 3
1 1 1 1 1 1
5 1
1 3 2 1 4
16 2
6 3 7 5 13 6 7 6 3 5 13 7 6 4 3 6
16 3
6 3 7 5 13 6 7 6 3 5 13 7 6 4 3 6
16 4
6 3 7 5 13 6 7 6 3 5 13 7 6 4 3 6
3
4
14
5
4
提示
Explanation of sample 1.
In the first test case, the drones’ energy levels evolve as follows:
- at the beginning, ;
- after 1 operation, ;
- after 2 operations, ;
- after 3 operations, .
After 3 operations, every energy level appears at most 3 times, so the process stops.
In the second test case, the energy levels change as follows: $[1, 3, 2, 1, 4] \to [1, 3, 2, 2, 4] \to [1, 3, 2, 3, 4] \to [1, 3, 2, 4, 4] \to [1, 3, 2, 4, 5]$. The process stops after 4 operations.