#P13008. 【MX-X13-T3】「KDOI-12」只有失去光明,才能逃脱黑暗。
【MX-X13-T3】「KDOI-12」只有失去光明,才能逃脱黑暗。
Description
Given a non-negative integer , you need to transform it into through a series of operations with the minimum cost. Each operation is defined as follows:
- Choose an integer , and pay a cost of to either add or subtract from .
Note: You do not need to ensure that remains non-negative during the operations.
Input Format
For each test case, output a single non-negative integer—the minimum cost required to transform into .
Output Format
For each test case, output a single non-negative integer—the minimum cost required to transform into .
5
2 4 1
2 5
2 5 2
2 5 2
3 9 2
1 2 3
4 23 3
1 5 2 4
1 114 5
1 4 1 9 19 8
4
4
5
11
29
Hint
Sample Explanation
For the second test case in the sample input, the following two operations transform into with the minimum cost:
- Choose , perform , resulting in with a cost of .
- Choose , perform , resulting in with an additional cost of , totaling .
Data Range
This problem uses bundled testing.
| Subtask | Points | ||||
|---|---|---|---|---|---|
For all test cases:
- ,
- ,
- ,
- .
Hint
Please use fast input methods for reading data.
Translated by DeepSeek V3.
京公网安备 11011102002149号