{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n #problem-body \u003e pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv id\u003d\"problem-body\"\u003e\n\t\u003cp\u003eA certain string-processing language allows the programmer to break a string into two pieces. Since this involves copying the old string, it costs n units of time to break a string of n characters into two pieces. Suppose a programmer wants to break a string into many pieces. The order in which the breaks are made can affect the total amount of time used. For example, suppose we wish to break a 20 character string after characters 3, 8, and 10 (numbering the characters in ascending order from the left-hand end, starting from 1). If the breaks are made in left-to-right order, then the first break cost 20 units of time, the second break costs 17 units of time, and the third breaks costs 12 units of time, a total of 49 units of time (see the sample below). If the breaks are made in right-to-left order, then the first break costs 20 units of time, the second break costs 10 units of time, and the third break costs 8 units of time, a total of 38 units of time.\u003c/p\u003e\r\n\u003cp\u003eThe cost of making the breaks in left-to-right order:\u003c/p\u003e\r\n\u003cpre\u003ethisisastringofchars (original)\r\nthi sisastringofchars (cost: 20 units)\r\nthi sisas tringofchars (cost: 17 units)\r\nthi sisas tr ingofchars (cost: 12 units)\r\n Total: 49 units.\u003c/pre\u003e\r\n\u003cp\u003eThe cost of making the breaks in right-to-left order:\u003c/p\u003e\r\n\u003cpre\u003ethisisastringofchars (original)\r\nthisisastr ingofchars (cost: 20 units)\r\nthisisas tr ingofchars (cost: 10 units)\r\nthi sisas tr ingofchars (cost: 8 units)\r\n Total: 38 units.\u003c/pre\u003e\r\n\u003cp\u003e\u003cstrong\u003eInput:\u003c/strong\u003e\u003c/p\u003e\r\n\u003cp\u003eThere are several test cases! In each test case, the first line contains 2 integers N (2\u0026lt;\u003dN\u0026lt;\u003d10000000) and M (1\u0026lt;\u003dM\u0026lt;\u003d1000, M\u003cn). n is the original length of string, and m number breaks. following lines contain integers mi (1\u003c\u003d\"Mi\u003cN)\" in ascending order that represent breaking positions from strings left-hand end. read input till eof.\u003c p\u003e\r\n\u003c/n).\u003e\u003c/p\u003e\u003cp\u003e(There wont be more than \u003cstrong\u003e100\u003c/strong\u003e cases)\u003c/p\u003e\r\n\u003cp\u003e\u003cstrong\u003eOutput:\u003c/strong\u003e\u003c/p\u003e\r\n\u003cp\u003eFor each test case, output in one line the least cost to make all the breakings.\u003c/p\u003e\r\n\u003cp\u003e\u003cstrong\u003eSample Input:\u003c/strong\u003e\u003c/p\u003e\r\n\u003cpre\u003e20 3\u003cbr\u003e3 8 10\u003cbr\u003e20 4\u003cbr\u003e2 3 8 10\u003c/pre\u003e\r\n\u003cp\u003e\u003cstrong\u003eSample Output:\u003c/strong\u003e\u003c/p\u003e\r\n\u003cpre\u003e37\u003cbr\u003e40\u003c/pre\u003e\r\n\u003chr\u003e\n\u003c/div\u003e"}}]}