TopCoder

Thumb hsnu2016
Adrien Wu
$ \begin{align} AC \times 2^9 \\ \text{New TIOJ ?} \end{align} $

User's AC Ratio

80.0% (4/5)

Submission's AC Ratio

72.7% (8/11)

Description

在一條線狀的草地上,有N叢草。你可以把他視為數線上的N個數(1 <= N <= 1,000),這些數分別在一些整數點上。
Bessie是一隻牛,從位置L出發,想要把所有這些草吃完。定義一株草”不新鮮度”是從開始到Bessie吃到該株草所過的時間。如今Bessie希望在吃到這些草的同時,吃所有草的”不新鮮度”總和可以最小。請找出最小的”不新鮮度”總和是多少。

(原文)
A long, linear field has N (1 <= N <= 1,000) clumps of grass at unique integer locations on what will be treated as a number line. Think of the clumps as points on the number line.
Bessie starts at some specified integer location L on the number line (1 <= L <= 1,000,000) and traverses the number line in the two possible directions (sometimes reversing her direction) in order to reach and eat all the clumps. She moves at a constant speed (one unit of distance in one unit of time), and eats a clump instantly
when she encounters it.
Clumps that aren't eaten for a while get stale. We say the ``staleness'' of a clump is the amount of time that elapses from when Bessie starts moving until she eats a clump. Bessie wants to minimize the total staleness of all the clumps she eats.
Find the minimum total staleness that Bessie can achieve while eating all the clumps.

Input Format

第一行有兩個整數N和L,代表有幾株草,以及開始的位置(1 <= L <= 1,000,000)
接下來N行每行有一個整數P,代表某株草在數線上的位置。

(原文)
* Line 1 : Two space-separated integers: N and L.
* Lines 2..N+1: Each line contains a single integer giving the position P of a clump (1 <= P <= 1,000,000).

Output Format

請輸出一個整數,代表最小的”不新鮮度”總和。

(原文)
* Line 1: A single integer: the minimum total staleness Bessie can achieve while eating all the clumps.

Sample Input

4 10
1
9
11
19

Sample Output

44

Hints

對於範例I/O, 可以這麼做:
* start at position 10 at time 0
* move to position 9, arriving at time 1
* move to position 11, arriving at time 3
* move to position 19, arriving at time 11
* move to position 1, arriving at time 29
giving her a total staleness of 1+3+11+29 = 44. There are other routes with the same total staleness, but no route with a smaller one.

Problem Source

原TIOJ1090 / USACO Gold Demo, 2005 Nov。Translation/Problem Setter: kelvin。

Subtasks

For Testdata: 0 ~ 0, Score: 10
For Testdata: 1 ~ 1, Score: 10
For Testdata: 2 ~ 2, Score: 10
For Testdata: 3 ~ 3, Score: 10
For Testdata: 4 ~ 4, Score: 10
For Testdata: 5 ~ 5, Score: 10
For Testdata: 6 ~ 6, Score: 10
For Testdata: 7 ~ 7, Score: 10
For Testdata: 8 ~ 8, Score: 10
For Testdata: 9 ~ 9, Score: 10
No. Time Limit (ms) Memory Limit (KiB)
0 1000 65536
1 1000 65536
2 1000 65536
3 1000 65536
4 1000 65536
5 1000 65536
6 1000 65536
7 1000 65536
8 1000 65536
9 1000 65536