#abc307g. G - Approximate Equalization
G - Approximate Equalization
Score : points
问题描述
给定一个长度为 的整数序列:。
高桥可以按照任意顺序执行以下两种操作任意次,包括零次。
- 选择一个整数 ,满足 ,将 减 并将 加 。
- 选择一个整数 ,满足 ,将 加 并将 减 。
求解使得序列 满足以下条件所需的最小操作次数:
- 对于任何一对在 和 之间的整数 ,有 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given an integer sequence of length : .
Takahashi can perform the following two operations any number of times, possibly zero, in any order.
- Choose an integer such that , and decrease by and increase by .
- Choose an integer such that , and increase by and decrease by .
Find the minimum number of operations required to make the sequence satisfy the following condition:
- for any pair of integers between and , inclusive.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print a single line containing the minimum number of operations required to make the sequence satisfy the condition in the problem statement.
Sample Input 1
3
2 7 6
Sample Output 1
4
You can make satisfy the condition with four operations as follows.
- Choose , and increase by and decrease by , making .
- Choose , and increase by and decrease by , making .
- Choose , and increase by and decrease by , making .
- Choose , and increase by and decrease by , making .
This is the minimum number of operations required, so print .
Sample Input 2
3
-2 -5 -2
Sample Output 2
2
You can make satisfy the condition with two operations as follows:
- Choose , and decrease by and increase by , making .
- Choose , and increase by and decrease by , making .
This is the minimum number of operations required, so print .
Sample Input 3
5
1 1 1 1 -7
Sample Output 3
13
By performing the operations appropriately, with operations you can make , which satisfies the condition in the problem statement. It is impossible to satisfy it with or fewer operations, so print .
update @ 2024/3/10 08:42:35