#P1109. Student Group Rebalancing
Student Group Rebalancing
Student Group Rebalancing
Student Group Rebalancing
You are given n groups of students. Each group initially has a certain number of students. In addition, you are provided with two integers \(L\) and \(R\) (with \(L \le R\)), which represent the lower and upper bound, respectively, on the number of students allowed in each group. In one move, you may select a student from one group and move that student to any other group. Your task is to determine the minimum number of moves required so that, after all moves, the number of students in every group is within the range \([L, R]\).
Note: It is guaranteed that a valid final configuration exists.
inputFormat
The input consists of two lines:
- The first line contains three integers \(n\), \(L\), and \(R\) — the number of groups, the lower bound, and the upper bound respectively.
- The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\), where \(a_i\) is the initial number of students in the \(i\)-th group.
outputFormat
Output a single integer — the minimum number of moves required to make the number of students in every group fall within the interval \([L, R]\).
sample
3 3 5
1 4 8
3