#1742. [Usaco2005 nov]Grazing on the Run 边跑边吃草

[Usaco2005 nov]Grazing on the Run 边跑边吃草

题目描述

John 养了一只叫 Joseph 的奶牛。一次她去放牛,来到一个非常长的一片地,长度为 ll,上面有 nn 块地方长了茂盛的草。我们可以认为草地是一个数轴上的一些点。Joseph 看到这些草非常兴奋,它想把它们全部吃光。于是它开始左右行走,吃草。John 和 Joseph 开始的时候站在 pp 位置。Joseph 的移动速度是一个单位时间一个单位距离。不幸的是,草如果长时间不吃,就会腐败。我们定义一堆草的腐败值是从 Joseph 开始吃草到吃到这堆草的总时间。Joseph 可不想吃太腐败的草,它请 John 帮它安排一个路线,使得它吃完所有的草后,总腐败值最小。John 的数学很烂,她不知道该怎样做,你能帮她么?

输入格式

  • Line 11: Two space-separated integers: nn and ll.
  • Lines 2n+12\dots n+1: Each line contains a single integer giving the position pp of a clump.

输出格式

  • Line 11: A single integer: the minimum total staleness Bessie can achieve while eating all the clumps.
4 10
1
9
11
19
44

样例说明

INPUT DETAILS:
Four clumps: at 1,9,111,9,11, and 1919. Bessie starts at location 1010.

OUTPUT DETAILS:
Bessie can follow this route:

  • start at position 1010 at time 00.
  • move to position 99, arriving at time 11.
  • move to position 1111, arriving at time 33.
  • move to position 1919, arriving at time 1111.
  • move to position 11, arriving at time 2929.

giving her a total staleness of 1+3+11+29=441+3+11+29 = 44. There are other routes with the same total staleness, but no route with a smaller one.

数据规模与约定

对于 100%100\% 的数据,n103n\le 10^31p1061 \le p \le 10^6

题目来源

Gold