atcoder#ABC255D. [ABC255D] ±1 Operation 2
[ABC255D] ±1 Operation 2
Score : points
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.
5 3
6 11 2 5 5
5
20
0
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.
10 5
1000000000 314159265 271828182 141421356 161803398 0 777777777 255255255 536870912 998244353
555555555
321654987
1000000000
789456123
0
3316905982
2811735560
5542639502
4275864946
4457360498
The output may not fit into -bit integers.