#abc313c. C - Approximate Equalization 2
C - Approximate Equalization 2
Score : points
问题描述
你给定一个整数序列 。你可以执行以下操作任意次数(包括零次)。
- 选择整数 和 ,满足 。将 减一,并将 加一。
找出使 中最小值与最大值之差最多为一时所需的最少操作次数。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given an integer sequence . You can perform the following operation any number of times (possibly zero).
- Choose integers and with . Decrease by one and increase by one.
Find the minimum number of operations required to make the difference between the minimum and maximum values of at most one.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
4
4 7 3 7
Sample Output 1
3
By the following three operations, the difference between the minimum and maximum values of becomes at most one.
- Choose and to make .
- Choose and to make .
- Choose and to make .
You cannot make the difference between maximum and minimum values of at most one by less than three operations, so the answer is .
Sample Input 2
1
313
Sample Output 2
0
Sample Input 3
10
999999997 999999999 4 3 2 4 999999990 8 999999991 999999993
Sample Output 3
2499999974
update @ 2024/3/10 08:55:11