100 atcoder#ABC074B. [ABC074B] Collecting Balls (Easy Version)
[ABC074B] Collecting Balls (Easy Version)
Score : points
Problem Statement
There are balls in the -plane. The coordinates of the -th of them is . Thus, we have one ball on each of the lines , , , .
In order to collect these balls, Snuke prepared robots, of type A and of type B. Then, he placed the -th type-A robot at coordinates , and the -th type-B robot at coordinates . Thus, now we have one type-A robot and one type-B robot on each of the lines , , , .
When activated, each type of robot will operate as follows.
- When a type-A robot is activated at coordinates , it will move to the position of the ball on the line , collect the ball, move back to its original position and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.
- When a type-B robot is activated at coordinates , it will move to the position of the ball on the line , collect the ball, move back to its original position and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.
Snuke will activate some of the robots to collect all of the balls. Find the minimum possible total distance covered by robots.
Constraints
- All input values are integers.
Inputs
Input is given from Standard Input in the following format:
Outputs
Print the minimum possible total distance covered by robots.
1
10
2
4
There are just one ball, one type-A robot and one type-B robot.
If the type-A robot is used to collect the ball, the distance from the robot to the ball is , and the distance from the ball to the original position of the robot is also , for a total distance of .
Similarly, if the type-B robot is used, the total distance covered will be .
Thus, the total distance covered will be minimized when the type-A robot is used. The output should be .
2
9
3 6
12
The total distance covered will be minimized when the first ball is collected by the type-A robot, and the second ball by the type-B robot.
5
20
11 12 9 17 12
74