#P11062. 【MX-X4-T2】「Jason-1」加法
【MX-X4-T2】「Jason-1」加法
Background
Original link: https://oier.team/problems/X4C。
Problem Description
Given two integers (possibly negative), you may perform any number of operations (including doing nothing). In each operation, you need to choose one of the following two forms:
- Operation 1: Assign to the sum of and , i.e., .
- Operation 2: Assign to the sum of and , i.e., .
Your goal is to minimize the absolute value of the difference between and , . Output the minimum value.
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases. For each test case:
- One line containing two integers .
Output Format
For each test case:
- Output one integer on a single line, the answer.
5
1 1
3 7
-4 1
-5 -8
4 0
0
3
0
3
0
2
-6 9
34 -51
0
0
Hint
[Sample Explanation #1]
For the 1st test case, one feasible plan is: perform no operations, and .
For the 2nd test case, one feasible plan is: first use operation 2, so is assigned to ; then use operation 1, so is assigned to . At this time, . It can be proven that this is the minimum value achievable.
For the 3rd test case, one feasible plan is: use operation 1 consecutively times, and is assigned to in order. At this time, and are equal, so .
For the 4th test case, one feasible plan is: perform no operations, and .
For the 5th test case, one feasible plan is: use operation 2, so is assigned to . At this time, .
[Sample Explanation #2]
For both test cases in this sample, you can first use operation 2 once, then use operation 1 three times, making the absolute difference .
[Constraints]
| Test Point ID | Special Property | Score |
|---|---|---|
| 1 | A | |
| 2 | B | |
| 3 | None |
- Special Property A: is guaranteed.
- Special Property B: is guaranteed.
For of the testdata, , .
Translated by ChatGPT 5