#P1109. 学生分组

学生分组

Description

There are nn groups of students. You are given the initial number of students in each group, and the upper bound RR and lower bound LL for each group size (with LRL \le R). In one operation, you may select one student from a group and move them to another group. What is the minimum number of operations required to make the sizes of all nn groups fall within [L,R][L, R]?

Input Format

The first line contains an integer nn, the number of student groups. The second line contains nn integers, the number of students in each group. The third line contains two integers L,RL, R, the lower and upper bounds.

Output Format

Output a single integer, the minimum number of moves. If it is impossible to satisfy the condition, output -1.

2
10 20
10 15

5

Hint

Constraints

For all testdata, it is guaranteed that 1n501 \le n \le 50.

Translated by ChatGPT 5