{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"A long, linear field has N (1 \u0026lt;\u003d N \u0026lt;\u003d 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.\r\u003cbr\u003e\r\u003cbr\u003eBessie starts at some specified integer location L on the number line (1 \u0026lt;\u003d L \u0026lt;\u003d 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.\r\u003cbr\u003e\r\u003cbr\u003eClumps that aren\u0027t 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.\r\u003cbr\u003e\r\u003cbr\u003eFind the minimum total staleness that Bessie can achieve while eating all the clumps."}},{"title":"Input","value":{"format":"HTML","content":"* Line 1 : Two space-separated integers: N and L.\r\u003cbr\u003e* Lines 2..N+1: Each line contains a single integer giving the position P of a clump (1 \u0026lt;\u003d P \u0026lt;\u003d 1,000,000).\r\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"* Line 1: A single integer: the minimum total staleness Bessie can achieve while eating all the clumps."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4 10\r\n1\r\n9\r\n11\r\n19\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e44\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"INPUT DETAILS:\r\u003cbr\u003eFour clumps: at 1, 9, 11, and 19. Bessie starts at location 10.\r\u003cbr\u003e\r\u003cbr\u003eOUTPUT DETAILS:\r\u003cbr\u003eBessie can follow this route:\r\u003cbr\u003e* start at position 10 at time 0\r\u003cbr\u003e* move to position 9, arriving at time 1\r\u003cbr\u003e* move to position 11, arriving at time 3\r\u003cbr\u003e* move to position 19, arriving at time 11\r\u003cbr\u003e* move to position 1, arriving at time 29"}}]}