문제
Problem 2: Taxi [Mark Gordon, Richard Peng, 2013]
Bessie is running a taxi service for the other cows on the farm. The cows have been gathering at different locations along a fence of length M
To save gas, Bessie would like to minimize the amount she has to drive. Given the starting and ending positions of each of the N cows
Bessie starts at the leftmost point of the fence, position 0, and must finish her journey at the rightmost point on the fence, position M.
입력
* Line 1: N and M separated by a space.
* Lines 2..1+N: The
출력
* Line 1: A single integer indicating the total amount of driving Bessie must do. Note that the result may not fit into a 32 bit integer.
예제1
2 10
0 9
6 5
12
INPUT DETAILS:
There are two cows waiting to be transported along a fence of length 10. The first cow wants to go from position 0 (where Bessie starts) to position 9. The second cow wishes to go from position 6 to position 5.
OUTPUT DETAILS:
Bessie picks up the first cow at position 0 and drives to position 6. There she drops off the first cow, delivers the second cow to her destination and returns to pick up the first cow. She drops off the first cow and then drives the remainder of the way to the right side of the fence.