#abc255d. D - ±1 Operation 2
D - ±1 Operation 2
Score : points
问题描述
给定一个长度为 的序列:。以下对该序列的操作被称为 操作。
- 首先,选择一个整数 ,满足 。
- 接着,选择并执行以下操作之一:
- 将 加上 。
- 从 减去 。
回答 个问题。 第 个问题是:
- 考虑执行零次或多次操作以将 中的所有元素变为 。找出完成此目标所需的最少操作次数。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a sequence of length : . The following action on this sequence is called an operation.
- First, choose an integer such that .
- Next, choose and do one of the following.
- Add to .
- Subtract from .
Answer questions. The -th question is the following.
- Consider performing zero or more operations to change every element of to . Find the minimum number of operations required to do so.
Constraints
-
All values in input are integers.
-
-
-
的数据, 。
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the answer to the -th question as an integer.
Sample Input 1
5 3
6 11 2 5 5
5
20
0
Sample Output 1
10
71
29
We have and three questions in this input.
For the -st question, you can change every element of to in operations as follows.
- Subtract from .
- Subtract from six times.
- Add to three times.
It is impossible to change every element of to in or fewer operations.
For the -nd question, you can change every element of to in operations.
For the -rd question, you can change every element of to in operations.
Sample Input 2
10 5
1000000000 314159265 271828182 141421356 161803398 0 777777777 255255255 536870912 998244353
555555555
321654987
1000000000
789456123
0
Sample Output 2
3316905982
2811735560
5542639502
4275864946
4457360498
The output may not fit into -bit integers.
update @ 2024/3/10 10:51:40