luogu#P9581. 「MXOI Round 1」宝箱
「MXOI Round 1」宝箱
Problem Description
Little C likes collecting treasure chests in a game called Yuanshen (pinyin).
Now, Little C is on a number line, and he is at the origin of the number line.
At the same time, there are two treasure chests on this number line, with coordinates and .
As long as Little C moves to the position of a treasure chest, we consider that Little C has collected this treasure chest. In particular, if Little C is initially at the position of a treasure chest, then he can collect this treasure chest directly. If the two treasure chests are at the same position, then he can collect both treasure chests at the same time.
Each time, Little C can move 1 unit length along the positive direction or the negative direction of the number line. Little C wants to know: to collect both treasure chests, what is the minimum number of moves needed?
Input Format
Two integers .
Output Format
One integer, representing the minimum number of moves Little C needs to collect both treasure chests.
1 -1
3
-5 0
5
51 -154
256
Hint
Sample Explanation #1.
Little C can first move time in the negative direction of the number line, and then move times in the positive direction.
It can be proven that Little C needs at least moves.
Sample Explanation #2.
Little C can directly move times in the negative direction of the number line.
It can be proven that Little C needs at least moves.
Constraints.
For of the testdata, .
| Test Point ID | Special Property |
|---|---|
| Guaranteed that | |
| Guaranteed that | |
| None |
Translated by ChatGPT 5