P2954 [USACO09OPEN] Grazing2 S
题目描述
Farmer John has N (2
输入格式
\* Line 1: Two space-separated integers: N and S
\* Lines 2..N+1: Line i+1 contains the single integer: P\_i
输出格式
\* Line 1: A single integer: the minimum total distance the cows have to travel. This number is guaranteed to be under 1,000,000,000 (thus fitting easily into a signed 32-bit integer).
说明/提示
1 2 3 4 5 6 7 8 9 10
Cow Locs | A | B | C | . | . | . | . | D | E | . |
Cows move from stall 2 to 3, 3 to 5, and 9 to 10. The total distance moved is 1 + 2 + 1 = 4. The final positions of the cows are in stalls 1, 3, 5, 8, and 10.
1 2 3 4 5 6 7 8 9 10
Init Stall | A | B | C | . | . | . | . | D | E | . |
Final Stall | A | . | B | . | C | . | . | D | . | E |
Distance moved | 0 | . | 1 | . | 2 | . | . | 0 | . | 1 |