problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
262k
1.05M
problem_description
stringlengths
48
1.55k
codes
stringlengths
35
98.9k
status
stringlengths
28
1.7k
submission_ids
stringlengths
28
1.41k
memories
stringlengths
13
808
cpu_times
stringlengths
11
610
code_sizes
stringlengths
7
505
p03137
u127499732
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
["def main():\n n, m, *x = map(int, open(0).read().split())\n if m >= n:\n print(0)\n return\n x.sort()\n a = [x[i + 1] - x[i] for i in range(m - 1)]\n a.sort()\n ans = sum(a) - sum(a[-n+1:])\n print(ans)\n\nif __name__ == '__main__':\n main()\n", "def main():\n n, m, *x = map(int, open(0).read().split())\n if n >= m:\n print(0)\n return\n x.sort()\n a = [x[i + 1] - x[i] for i in range(m - 1)]\n a.sort()\n if n == 1:\n print(sum(a))\n return\n ans = sum(a) - sum(a[-n+1:])\n print(ans)\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s832915360', 's939800456']
[13964.0, 13964.0]
[61.0, 99.0]
[268, 320]
p03137
u143322814
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m = map(int,input().split())\nx = list(map(int,input().split()))\n\nif n >= m:\n print(0)\nelse:\n x = sorted(x)\n x = [x[i+1]-x[i] for i in range(len(x)-1)]\n\n x = sorted(x, reverse=True)\n x = xx[n-1:]\n ans = 0\n for i in x:\n ans+=i\n print(ans)\n', 'n,m = map(int,input().split())\nx = list(map(int,input().split()))\n\nif n >= m:\n print(0)\nelse:\n x = sorted(x)\n x = [x[i+1]-x[i] for i in range(len(x)-1)]\n\n x = sorted(x, reverse=True)\n x = x[n-1:]\n ans = 0\n for i in x:\n ans+=i\n print(ans)\n']
['Runtime Error', 'Accepted']
['s124386307', 's871221760']
[13968.0, 13968.0]
[119.0, 106.0]
[270, 269]
p03137
u145078501
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['# -*- coding: utf-8 -*-\nfrom itertools import starmap\n\nn, m = map(int, input().split())\nl = sorted(list(map(int, input().split())))\ndivcount = n - 1\n\nif n == 1:\n print(max(l) - min(l))\nelse:\n divl = sorted(list(starmap(lambda a,b: a - b, zip(l[1:], l[:m - 2])), reverse = True)\n for i in range(divcount):\n del divl[0]\n \n print (sum(divl))\n', '# -*- coding: utf-8 -*-\n \nn, m = map(int, input().split())\nl = sorted(list(map(int, input().split())))\ndivcount = n - 1\n \nl1 = l[1:]\nl2 = l[:m - 1]\ndivl = []\n \nfor i in range(m - 1):\n divl.append(l1[i] - l2[i])\n \ndivl.sort(reverse = True)\n \nif n == 1:\n print(max(l) - min(l))\nelse:\n if m > n:\n for i in range(divcount):\n del divl[0]\n \n print (sum(divl))\n \n else:\n print(0)']
['Runtime Error', 'Accepted']
['s271630869', 's424931040']
[2940.0, 13968.0]
[17.0, 1534.0]
[361, 422]
p03137
u151005508
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N, M = map(int, input().split())\nX=list(map(int, input().split()))\nX=sorted(X)\ndistance=[]\nfor i in range(M-1):\n distance.append(X[i+1]-X[i])\n\n\ndistance=sorted(distance, reverse=True)\nprint(distance)\nanswer=sum(distance[(N-1):])\nprint(answer)', 'N, M = map(int, input().split())\nX=list(map(int, input().split()))\nX=sorted(X)\ndistance=[]\nfor i in range(M-1):\n distance.append(X[i+1]-X[i])\n\n\ndistance=sorted(distance, reverse=True)\n#print(distance)\nanswer=sum(distance[(N-1):])\nprint(answer)']
['Wrong Answer', 'Accepted']
['s834942247', 's903425982']
[13968.0, 13968.0]
[120.0, 117.0]
[245, 246]
p03137
u151625340
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N, M = input().split()\nX = list(map(int, input().split()))\n\nif N >= M:\n print(0)\nelse:\n X.sort()\n L = []\n for i in range(M-1):\n L.append(X[i+1]-X[i])\n L.sort(reverse=True)\n print(X[M]-X[0]-sum(L[:N-1]))\n', 'N, M = input().split()\nX = list(map(int, input().split()))\n\nif N >= M:\n print(0)\nelse:\n X.sort()\n L = []\n for i in range(M-1):\n L.append(X[i+1]-X[i])\n L.sort(reverse=True)\n print(X[M-1]-X[0]-sum(L[:N-1]))\n', 'N, M = input().split()\nX = list(map(int, input().split()))\n\nif N >= M:\n print(0)\nelse:\n X.sort()\n L = []\n for i in range(M-1):\n L.append(X[i+1]-X[i])\n L.sort(reverse=True)\n print(X[M-1]-X[0]-sum(L[:N-1]))\n', 'N, M = map(int, input().split())\nX = list(map(int, input().split()))\n\nif N >= M:\n print(0)\nelse:\n X.sort()\n L = []\n for i in range(M-1):\n L.append(X[i+1]-X[i])\n L.sort(reverse=True)\n print(X[M-1]-X[0]-sum(L[:N-1]))\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s252066742', 's543464763', 's636400776', 's040872584']
[13964.0, 13960.0, 13968.0, 13960.0]
[69.0, 71.0, 70.0, 115.0]
[228, 214, 230, 240]
p03137
u159335277
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n, m = list(map(int, input().split()))\nx = list(map(int, input().split()))\n\nxs = []\nfor i in range(0, len(x)-1):\n xs.append(x[i+1] - x[i])\nxs.sort()\n\nans = 0\nfor i in range(0, len(xs)):\n if m - i <= n:\n break\n ans += xs[i]\nprint(ans)', 'n, m = list(map(int, input().split()))\nx = list(map(int, input().split()))\nx.sort()\nxs = []\nfor i in range(0, len(x)-1):\n xs.append(x[i+1] - x[i])\nxs.sort()\n\nans = 0\nfor i in range(0, len(xs)):\n if m - i <= n:\n break\n ans += xs[i]\nprint(ans)']
['Wrong Answer', 'Accepted']
['s002098134', 's569706954']
[13968.0, 13960.0]
[114.0, 123.0]
[239, 247]
p03137
u166306121
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M = map(int,input().split())\nX = list(map(int,input().split()))\nX.sort()\nsa = [0 for i in range(M-1)]\n# print(X)\nfor i in range(M-1):\n sa[i] = X[i+1]-X[i]\nsa = sorted(sa)\nprint(sa)\nif N >= M:\n print(0)\nelse:\n print(sum(sa[0:-N+1]))', 'N,M = map(int,input().split())\nX = list(map(int,input().split()))\nX.sort()\nsa = [0 for i in range(M-1)]\n# print(X)\nfor i in range(M-1):\n sa[i] = X[i+1]-X[i]\nsa = sorted(sa)\n# print(sa)\nif N >= M:\n print(0)\nelif N == 1:\n print(sum(sa))\nelse:\n print(sum(sa[0:-N+1]))']
['Wrong Answer', 'Accepted']
['s665049388', 's615987559']
[13968.0, 13968.0]
[120.0, 114.0]
[242, 276]
p03137
u170324846
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['NM = [int(x) for x in input().split()]\nN = NM[0]\nM = NM[1]\nX = [int(x) for x in input().split()]\nX.sort()\nprint(X)\nLL = 0\nif N > M:\n #print(LL)\nelse:\n L = [0] * (M - 1)\n for i in range (0, M - 1):\n L[i] = X[i + 1] - X[i]\n L.sort()\n #print(L)\n for i in range(0, M - N):\n LL += L[i]\n print(LL)', 'NM = [int(x) for x in input().split()]\nN = NM[0]\nM = NM[1]\nX = [int(x) for x in input().split()]\nX.sort()\nprint(X)\nLL = 0\nif N > M:\n print(LL)\nelse:\n L = [0] * (M - 1)\n for i in range (0, M - 1):\n L[i] = X[i + 1] - X[i]\n L.sort()\n print(L)\n for i in range(0, M - N):\n LL += L[i]\n print(LL)', 'NM = [int(x) for x in input().split()]\nN = NM[0]\nM = NM[1]\nX = [int(x) for x in input().split()]\nX.sort()\n#print(X)\nLL = 0\nif N > M:\n print(LL)\nelse:\n L = [0] * (M - 1)\n for i in range (0, M - 1):\n L[i] = X[i + 1] - X[i]\n L.sort()\n #print(L)\n for i in range(0, M - N):\n LL += L[i]\n print(LL)']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s327088421', 's743490471', 's198650901']
[2940.0, 13840.0, 13840.0]
[18.0, 137.0, 119.0]
[326, 324, 326]
p03137
u172035535
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M = map(int,input().split())\nX = sorted(map(int,input().split()))\nif X[0] < 0:\n X[0] *= -1\nfor i in range(1,M):\n X[i] = X[0]+X[i]\nX[0] = 0\nmean = max(X)/N\nans = 0\nfor i in range(len(X)):\n if N == 0:\n break\n for j in range(i+1,len(X)):\n if N == 0:\n break\n if X[j]-X[i] >= mean:\n ans = X[j-1]-X[i]\n N -= 1\n break\n mean = (max(X)-X[i])//N\n for j in range(i+1,len(X)):\n if X[j]-X[i] >= mean and N != 0:\n ans = X[j-1]-X[i]\n N -= 1\n break\nprint(ans)', 'N,M = map(int,input().split())\nX = sorted(map(int,input().split()))\nL = sorted([X[i+1]-X[i] for i in range(M-1)])\nif M < L:print(0)\nelse:print(sum(L[:(M-N)]))', 'N,M = map(int,input().split())\nX = sorted(map(int,input().split()))\nx = []\nfor i in range(M-1):\n\tx.append(abs(X[i]-X[i+1]))\nx.sort(reverse=1)\nif N >= M:\n\tprint(0)\nelse:\n\tprint(sum(x[N-1:]))']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s568910474', 's766517650', 's088590353']
[13960.0, 13960.0, 13968.0]
[2104.0, 104.0, 113.0]
[592, 158, 189]
p03137
u174273188
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['def solve():\n n, m = map(int, input().split())\n x = list(map(int, input().split()))\n x.sort()\n diff = [x[i + 1] - x[i] for i in range(m)]\n diff.sort(reverse=True)\n return sum(diff[n - 1:])\n\n\nif __name__ == "__main__":\n print(solve())\n', 'def solve():\n n, m = map(int, input().split())\n x = sorted(list(map(int, input().split())))\n diff = sorted([x[i + 1] - x[i] for i in range(m)], reverse=True)\n return sum(diff[n - 1:])\n\n\nif __name__ == "__main__":\n print(solve())\n', 'def solve():\n n, m = map(int, input().split())\n if n >= m:\n return 0\n x = sorted(list(map(int, input().split())))\n diff = sorted([x[i + 1] - x[i] for i in range(m)], reverse=True)\n return sum(diff[n - 1:])\n\n\nif __name__ == "__main__":\n print(solve())\n', 'def solve():\n n, m = map(int, input().split())\n x = sorted(list(map(int, input().split())))\n diff = sorted([x[i + 1] - x[i] for i in range(m - 1)], reverse=True)\n return sum(diff[n - 1:])\n\n\nif __name__ == "__main__":\n print(solve())\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s563492969', 's817958540', 's861173304', 's819419295']
[13968.0, 13960.0, 13968.0, 13968.0]
[87.0, 89.0, 88.0, 99.0]
[255, 244, 276, 248]
p03137
u175590965
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m = map(int,input().split())\nx = sorted(map(int,input().split()))\nl = sorted([x[i+1]-x[i]for i in range(m-1)])\nif n >=m:\n print(0)\nelse:\n print(sum(l)-sum([-i-1]for i in range(n-1)))', 'n, m = map(int, input().split())\nx = sorted(set(map(int, input().split())))\nt = []\nfor i, j in zip(x, x[1:]):\n t += [abs(i - j)]\nt = sorted(t, reverse=True)\nprint(sum(t[n-1:]))\n']
['Runtime Error', 'Accepted']
['s614420761', 's473301603']
[13960.0, 18956.0]
[106.0, 94.0]
[190, 180]
p03137
u177220795
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M = map(int,input().split())\nX=[int(i) for i in input().split()]\nX.sort()\n\nY=list()\nfor i in range(M)[1:]\n Y.append(X[i]-X[i-1])\n\nY.sort()\n\nif N==1:\n print(sum(Y))\nelse:\n print(sum(Y[:-(N-1)]))\n', 'N,M = map(int,input().split())\nX=[int(i) for i in input().split()]\nX.sort()\n\nif N==1:\n print(X[M-1]-X[0])\nelif N>=M:\n print(0)\nelif N+1=M:\n print(X[0])\nelse:\n Y=list()\n [Y.append(X[i]-X[i-1]) for i in range(M)[1:]]\n Y.sort()\n print(sum(Y[:-(N-1)]))\n', 'N=int(input())\nM=int(input())\n\nX=sorted([int(i) for i in input().split()])\n\nY=list()\nbefore=X[0]\nfor i in X:\n diff = i - before\n if diff == 0:\n continue\n Y.append(diff)\n before = i\n\nY=sorted(Y)\n\nprint(sum(Y[:-(N-1)]))\n\n', 'N,M = map(int,input().split())\nX=sorted(map(int, input().split()))\nif N==1:\n print(X[M-1]-X[0])\nelif N>=M:\n print(0)\nelse:\n print(sum(sorted([i-j for i,j in zip(X[1:],X)],reverse=True)[N-1:]))']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s391849072', 's532163937', 's849474986', 's507760012']
[2940.0, 2940.0, 3060.0, 13968.0]
[17.0, 17.0, 17.0, 96.0]
[199, 256, 226, 195]
p03137
u177411511
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['import sys\n\nstdin = sys.stdin\n\nni = lambda: int(ns())\nna = lambda: list(map(int, stdin.readline().split()))\nns = lambda: stdin.readline().rstrip() # ignore trailing spaces\n\nn, m = na()\nli = na()\nls = []\nif len(li) - 1 < n - 1:\n print(0)\nelse:\n list.sort(li)\n for i in range(len(li) - 1):\n ls.append(li[i + 1] - li[i])\n list.sort(ls)\n print(ls)\n print(ls[:-(n-1)])\n if n - 1 > 0:\n print(sum(ls[:-(n-1)]))\n else:\n print(0)', 'import sys\n\nstdin = sys.stdin\n\nni = lambda: int(ns())\nna = lambda: list(map(int, stdin.readline().split()))\nns = lambda: stdin.readline().rstrip() # ignore trailing spaces\n\nn, m = na()\nli = na()\nls = []\nlist.sort(li)\nfor i in range(len(li) - 1):\n ls.append(li[i + 1] - li[i])\nls = sorted(ls, reverse=True)\nprint(sum(ls[n-1:]))']
['Wrong Answer', 'Accepted']
['s696364299', 's217759506']
[13556.0, 13308.0]
[121.0, 113.0]
[466, 330]
p03137
u178192749
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m = map(int,input().split())\nx = list(map(int,input().split()))\nif m =< n:\n print(0)\n quit()\n\nx.sort()\ndist_l = [0] * (m-1)\n\nfor i in range(m-1):\n dist_l[i] = x[i+1] - x[i]\n\ndist_l.sort()\nprint(sum(dist_l[:-(n-1)]))', 'n,m = map(int,input().split())\nx = list(map(int,input().split()))\n\nx.sort()\ndist_l = [0] * (m-1)\n\nfor i in range(m-1):\n dist_l[i] = x[i+1] - x[i]\n\ndist_l.sort()\nprint(sum(dist_l[:-(n-1)]) if n !=1 else sum(dist_l))']
['Runtime Error', 'Accepted']
['s608227527', 's641102560']
[2940.0, 13968.0]
[17.0, 109.0]
[226, 217]
p03137
u183896397
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,C,K = map(int,input().split())\nT = []\nfor _ in range(N):\n t = int(input())\n T.append(t)\nT.sort()\nangry = 0\nans = 0\nc = 0\nfor i in T:\n if angry == 0:\n angry = i + K\n c += 1\n if i >= angry :\n #print(i,angry)\n angry = i + K\n ans += 1\n c = 1\n if c == C:\n angry = 0\n ans += 1\n c = 0\n #print(ans,angry,c)\nif c > 0:\n ans += 1\nif C == 1:\n ans = C\nprint(ans) ', 'N,M = map(int,input().split())\nX = list(map(int,input().split()))\nX.sort()\nif M <= N :\n ans = 0\nelse:\n Y = []\n for i in range(M-1):\n Y.append(X[i+1] - X[i])\n Y.sort(reverse=True)\n ans = X[-1] - X[0]\n Y = Y[:N-1]\n for i in Y:\n ans -= i\nprint(ans)']
['Runtime Error', 'Accepted']
['s462724335', 's752359190']
[3064.0, 13968.0]
[17.0, 123.0]
[436, 280]
p03137
u187205913
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m = map(int,input().split())\nx = list(map(int,input().split()))\nx = sorted(x)\nd = []\nfor i in range(len(x)-1):\n d.append(x[i+1]-x[i])\nd = sorted(d)\nif n==1:\n print(x[-1]-x[0])\nelif n>=len(x):\n print(0)\nelse:\n ans = 0\n for i in range(n-1):\n ans+=d[-i-1]\n print(ans)', 'n,m = map(int,input().split())\nx = list(map(int,input().split()))\nx = sorted(x)\nd = []\nfor i in range(len(x)-1):\n d.append(x[i+1]-x[i])\nd = sorted(d)\nif n==1:\n print(x[-1]-x[0])\nelif n>=len(x):\n print(0)\nelse:\n print(d)\n dis = 0\n for i in range(n-1):\n dis+=d[-i-1]\n print(sum(d)-dis)', 'n,m = map(int,input().split())\nx = list(map(int,input().split()))\nx = sorted(x)\nd = []\nfor i in range(len(x)-1):\n d.append(x[i+1]-x[i])\nd = sorted(d)\nif n==1:\n print(x[-1]-x[0])\nelif n>=len(x):\n print(0)\nelse:\n dis = 0\n for i in range(n-1):\n dis+=d[-i-1]\n print(sum(d)-dis)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s747048172', 's908261673', 's304052751']
[13968.0, 13968.0, 13968.0]
[127.0, 138.0, 128.0]
[291, 311, 298]
p03137
u197300773
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['import sys\n\nN,M=map(int,input().split())\nx=list(map(int,input().split()))\nx.sort()\na=[x[i+1]-x[i] for i in range(M-1)]\n\nif N>=M:\n print(0)\n sys.exit()\n \nprint(sum(a[:M-N]))', 'import sys\n\nN,M=map(int,input().split())\nx=list(map(int,input().split()))\nx.sort()\na=[x[i+1]-x[i] for i in range(M-1)]\na.sort()\n\nif N>=M:\n print(0)\n sys.exit()\n \nprint(sum(a[:M-N]))']
['Wrong Answer', 'Accepted']
['s331217989', 's995324735']
[13968.0, 13960.0]
[93.0, 101.0]
[181, 190]
p03137
u198440493
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n, m = map(int, input().split())\nx = list(set(map(int, input().split())))\nl = [x[i+1]-x[i] for i in range(n-1)]\nl.sort(reverse=True)\nprint(sum(l[n-1:]))', 'n, m = map(int, input().split())\nx = list(map(int, input().split()))\nx.sort()\nl = [x[i+1]-x[i] for i in range(m-1)]\nl.sort(reverse=True)\nprint(x[-1]-x[0]-sum(l[:n-1]))']
['Runtime Error', 'Accepted']
['s841822764', 's863207468']
[18960.0, 13968.0]
[80.0, 103.0]
[152, 167]
p03137
u201660334
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n, m = map(int, input().split())\nx = list(map(int, input().split()))\nx.sort(\ny = []\nfor i in range(m - 1):\n y.append(x[i + 1] - x[i])\ny.sort()\ncount = 0\nfor i in range(m - n):\n count += y[i]\nprint(count)', 'n, m = map(int, input().split())\nx = list(map(int, input().split()))\nx.sort()\ny = []\nfor i in range(m - 1):\n y.append(x[i + 1] - x[i])\ny.sort()\ncount = 0\nfor i in range(m - n):\n count += y[i]\nprint(count)']
['Runtime Error', 'Accepted']
['s369633559', 's920058362']
[2940.0, 13960.0]
[17.0, 114.0]
[209, 210]
p03137
u201856486
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['# coding: utf-8\nimport sys\n\n# import math\n# import numpy as np\n\n\n"""Template"""\n\n\nclass IP:\n \n def __init__(self):\n self.input = sys.stdin.readline\n\n def I(self):\n \n return int(self.input())\n\n def S(self):\n \n return self.input()\n\n def IL(self):\n \n return list(map(int, self.input().split()))\n\n def SL(self):\n \n return list(map(str, self.input().split()))\n\n def ILS(self, n):\n \n return [int(self.input()) for _ in range(n)]\n\n def SLS(self, n):\n \n return [self.input() for _ in range(n)]\n\n def SILS(self, n):\n \n return [self.IL() for _ in range(n)]\n\n def SSLS(self, n):\n \n return [self.SL() for _ in range(n)]\n\n\nclass Idea:\n def __init__(self):\n pass\n\n def HF(self, p):\n \n return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))\n\n def Bfs2(self, a):\n \n \n # https://blog.rossywhite.com/2018/08/06/bit-search/\n \n value = []\n for i in range(1 << len(a)):\n output = []\n\n for j in range(len(a)):\n if self.bit_o(i, j):\n \n # output.append(a[j])\n output.append(a[j])\n value.append([format(i, \'b\').zfill(16), sum(output)])\n\n value.sort(key=lambda x: x[1])\n bin = [value[k][0] for k in range(len(value))]\n val = [value[k][1] for k in range(len(value))]\n return bin, val\n\n def S(self, s, r=0, m=-1):\n \n r = bool(r)\n if m == -1:\n s.sort(reverse=r)\n else:\n s.sort(reverse=r, key=lambda x: x[m])\n\n def bit_n(self, a, b):\n \n return bool((a >> b & 1) > 0)\n\n def bit_o(self, a, b):\n \n return bool(((a >> b) & 1) == 1)\n\n def ceil(self, x, y):\n \n return -(-x//y)\n\n def ave(self, a):\n \n return sum(a) / len(a)\n\n\n\n\n\ndef main():\n \n r, e = range, enumerate\n ip = IP()\n id = Idea()\n\n \n n, m = ip.IL()\n x = ip.IL()\n\n id.S(x)\n s = []\n for i in r(0, m-1):\n s.append(x[i+1] - x[i])\n\n id.S(s, 1)\n if m == 1:\n print(0)\n else:\n for _ in r(n-1):\n s.pop(0)\n print(sum(s))\n\n\nmain()\n', '# coding: utf-8\nimport sys\n\n# import math\n# import numpy as np\n\n\n"""Template"""\n\n\nclass IP:\n \n def __init__(self):\n self.input = sys.stdin.readline\n\n def I(self):\n \n return int(self.input())\n\n def S(self):\n \n return self.input()\n\n def IL(self):\n \n return list(map(int, self.input().split()))\n\n def SL(self):\n \n return list(map(str, self.input().split()))\n\n def ILS(self, n):\n \n return [int(self.input()) for _ in range(n)]\n\n def SLS(self, n):\n \n return [self.input() for _ in range(n)]\n\n def SILS(self, n):\n \n return [self.IL() for _ in range(n)]\n\n def SSLS(self, n):\n \n return [self.SL() for _ in range(n)]\n\n\nclass Idea:\n def __init__(self):\n pass\n\n def HF(self, p):\n \n return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))\n\n def Bfs2(self, a):\n \n \n # https://blog.rossywhite.com/2018/08/06/bit-search/\n \n value = []\n for i in range(1 << len(a)):\n output = []\n\n for j in range(len(a)):\n if self.bit_o(i, j):\n \n # output.append(a[j])\n output.append(a[j])\n value.append([format(i, \'b\').zfill(16), sum(output)])\n\n value.sort(key=lambda x: x[1])\n bin = [value[k][0] for k in range(len(value))]\n val = [value[k][1] for k in range(len(value))]\n return bin, val\n\n def S(self, s, r=0, m=-1):\n \n r = bool(r)\n if m == -1:\n s.sort(reverse=r)\n else:\n s.sort(reverse=r, key=lambda x: x[m])\n\n def bit_n(self, a, b):\n \n return bool((a >> b & 1) > 0)\n\n def bit_o(self, a, b):\n \n return bool(((a >> b) & 1) == 1)\n\n def ceil(self, x, y):\n \n return -(-x//y)\n\n def ave(self, a):\n \n return sum(a) / len(a)\n\n\n\n\n\ndef main():\n \n r, e = range, enumerate\n ip = IP()\n id = Idea()\n\n \n n, m = ip.IL()\n x = ip.IL()\n\n id.S(x)\n s = []\n for i in r(0, m-1):\n s.append(x[i+1] - x[i])\n\n id.S(s, 1)\n if m == 1:\n print(0)\n\n elif len(s) >= m:\n print(0)\n\n else:\n for _ in r(n-1):\n s.pop(0)\n if len(s) == 0:\n break\n print(sum(s))\n\n\nmain()\n']
['Runtime Error', 'Accepted']
['s835275138', 's513943234']
[3192.0, 13308.0]
[17.0, 1585.0]
[4734, 4823]
p03137
u204779264
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['import math\nimport sys\n\n\ndef solution(arr, moves):\n if len(arr) <= moves:\n return 0\n\n arr.sort()\n if moves == 1:\n return abs(arr[0] - arr[-1])\n\n diff = [None] * len(arr)\n diff[0] = abs(arr[0] - arr[1])\n diff[-1] = abs(arr[-2] - arr[-1])\n for i in range(1, len(arr) - 1):\n diff[i] = abs(arr[i] - arr[i - 1]) if abs(arr[i] - arr[i - 1]) > abs(arr[i] - arr[i + 1]) else abs(arr[i] - arr[i + 1])\n d = enumerate(diff)\n\n visited = {}\n current_positions = {}\n\n for i in list(reversed(sorted(d, key=lambda x: x[1])))[:moves]:\n visited[i[0]] = True\n current_positions[i[0]] = True\n\n counter = 0\n while len(visited) < len(arr):\n min_on_position = sys.maxsize\n minimum_element = None\n side = None\n for i in current_positions:\n if i - 1 not in visited and i > 0:\n if min_on_position > abs(arr[i - 1] - arr[i]):\n min_on_position = abs(arr[i - 1] - arr[i])\n minimum_element = i\n side = i - 1\n\n if i + 1 not in visited and i < len(arr) - 1:\n if min_on_position > abs(arr[i + 1] - arr[i]):\n min_on_position = abs(arr[i + 1] - arr[i])\n minimum_element = i\n side = i + 1\n\n\n current_positions[side] = True\n visited[side] = True\n counter += abs(arr[minimum_element] - arr[side])\n\n return counter\n\nfor i,line in enumerate(sys.stdin):\n if i == 0:\n N, M = int(line.split(" "))\n if i == 1:\n A = [int(i) for i in line.split(" ")]\n solution(A, M)\n\n# line = "-10 -3 0 9 -100 2 17"\n#\n\n# print("before")\n# a = [10,12,1,2,14]\n# b = [-100000]\n# print(solution(lines, 3))\n# print(solution(a, 2))\n# print(solution(b, 1))\n', 'import math\nimport sys\nfrom heapq import heappush, heappop\n\n\ndef solution(arr, moves):\n if len(arr) <= moves:\n return 0\n\n arr.sort()\n if moves == 1:\n return abs(arr[0] - arr[-1])\n\n heapq_max = []\n # place them then scan the array\n # right side of longest interval\n\n for i in range(0, len(arr) - 1):\n heappush(heapq_max, (-abs(arr[i] - arr[i + 1] ), i , i + 1))\n\n placed = [0]\n for _ in range(moves - 1):\n val = heappop(heapq_max)\n placed.append(val[2])\n\n placed.sort()\n counter = 0\n for i in range(len(placed) - 1):\n if (abs(placed[i] - placed[i + 1]) > 1):\n counter += abs(arr[placed[i]] - arr[placed[i + 1] - 1])\n if placed[-1] != len(arr) - 1:\n counter += abs(arr[placed[-1]] - arr[-1])\n return counter\n\n # visited = {}\n # current_positions = {}\n #\n \n # visited[i[0]] = True\n # current_positions[i[0]] = True\n #\n # counter = 0\n # while len(visited) < len(arr):\n # min_on_position = sys.maxsize\n # minimum_element = None\n # side = None\n \n # if i - 1 not in visited and i > 0:\n # if min_on_position > abs(arr[i - 1] - arr[i]):\n # min_on_position = abs(arr[i - 1] - arr[i])\n # minimum_element = i\n \n #\n # if i + 1 not in visited and i < len(arr) - 1:\n # if min_on_position > abs(arr[i + 1] - arr[i]):\n # min_on_position = abs(arr[i + 1] - arr[i])\n # minimum_element = i\n \n #\n #\n # current_positions[side] = True\n # visited[side] = True\n # counter += abs(arr[minimum_element] - arr[side])\n #\n # return counter\n\nfor i,line in enumerate(sys.stdin):\n if i == 0:\n M, N = line.split(" ")\n if i == 1:\n A = [int(i) for i in line.split(" ")]\n print(solution(A, int(M)))\n\n# line = "-10 -3 0 9 -100 2 17"\n#\n\n# a = [10,12,1,2,14]\n# b = [-100000]\n# print(solution(lines, 3))\n# print(solution(a, 2))\n# print(solution(b, 1))\n']
['Runtime Error', 'Accepted']
['s176908948', 's441249327']
[3192.0, 22720.0]
[18.0, 245.0]
[1851, 2269]
p03137
u217627525
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m=map(int,input().split())\nif n>=m:\n print(0)\nelse:\n x=list(map(int,input().split()))\n x.sort()\n y=[]\n for i in range(m-1):\n y.append(x[i+1]-x[i])\n y.sort(reverse=True)\n ans=x[-1]-x[0]\n for i in range(m-1):\n ans-=y[i]\n print(ans)', 'n,m=map(int,input().split())\nif n>=m:\n print(0)\n#elif n\nelse:\n x=list(map(int,input().split()))\n x.sort()\n y=[]\n for i in range(m-1):\n y.append(x[i+1]-x[i])\n y.sort(reverse=True)\n ans=x[-1]-x[0]\n for i in range(n-1):\n ans-=y[i]\n print(ans)']
['Wrong Answer', 'Accepted']
['s239619150', 's707106951']
[13968.0, 13960.0]
[126.0, 124.0]
[272, 280]
p03137
u217940964
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N, M = map(int, input().split())\n\nX = list(map(int, input().split()))\nX.sort()\n\nif N >= M:\n print(0)\n exit()\ndiffs = [X[i+1] - X[i] for i in range(M-1)]\ndiffs.sort()\nprint(sum[diffs[:N-M]])', 'N, M = map(int, input().split())\n\nX = list(map(int, input().split()))\nX.sort()\n\nif N >= M:\n print(0)\n exit()\ndiffs = [X[i+1] - X[i] for i in range(M-1)]\ndiffs.sort()\nprint(sum(diffs[:M-N]))']
['Runtime Error', 'Accepted']
['s034142637', 's377264329']
[13968.0, 13968.0]
[100.0, 104.0]
[195, 195]
p03137
u220462658
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['nandm = input().split()\nnumlist = input().split()\nN = int(nandm[0])\nM = int(nandm[1])\nif N >= M:\n print(0)\nelse:\n intlist = [int(num) for num in numlist]\n intlist.sort()\n subtract = [intlist[i + 1] - intlist[i] for i in range(len(intlist) - 1)]\n subtract.sort()\n print(sum(subtract[M - N]))', 'nandm = input().split()\nnumlist = input().split()\nN = int(nandm[0])\nM = int(nandm[1])\nif N >= M:\n print(0)\nelse:\n intlist = [int(num) for num in numlist]\n intlist.sort()\n subtract = [intlist[i + 1] - intlist[i] for i in range(len(intlist) - 1)]\n subtract.sort()\n print(sum(subtract[:(M - N)]))']
['Runtime Error', 'Accepted']
['s959453057', 's649944354']
[14728.0, 14736.0]
[107.0, 106.0]
[308, 311]
p03137
u221345507
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['import numpy as np\nimport sys\nN, M = map(int,input().split())\nX = list(map(int,input().split()))\nX.sort()\n\nX_list = list(np.diff(X))\n\nif M-N < 1:\n print(0)\n sys.exit()\n\nX_list.sort(reverse=True)\nsum(X_list[N-1:])', 'import numpy as np\nimport sys\nN, M = map(int,input().split())\nX = list(map(int,input().split()))\nX.sort()\n\nX_list = list(np.diff(X))\n\nif M-N < 1:\n print(0)\n sys.exit()\n\nX_list.sort(reverse=True)\nprint(sum(X_list[N-1:]))']
['Wrong Answer', 'Accepted']
['s408141099', 's941090379']
[23032.0, 23044.0]
[262.0, 261.0]
[218, 225]
p03137
u221998589
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['import numpy as np\n#from numba import njit\n\n\n#A = np.array(list(map(int, input().split())))\n(N,M) = map(int, input().split())\nX = map(int, input().split())\nX = sorted(X)\n\nY = []\nfor i in range(1,M):\n Y.append((i,X[i] - X[i-1]))\n\nY = sorted(Y, key=lambda x: (x[1]))\nY.reverse()\n\nZ = []\nlast = 0\nfor i in range(0,min(N-1, len(Y))):\n print((last, Y[i][0]))\n if last < Y[i][0]:\n Z.append(X[last:Y[i][0]])\n last = Y[i][0]\nZ.append(X[last:])\nif len(Z) == 0:\n Z.append(X)\n\ns = 0\nfor array in Z:\n if len(array) > 0:\n u = max(array)\n l = min(array)\n s += u - l\n\nprint(s)', 'import numpy as np\n#from numba import njit\n\n\n#A = np.array(list(map(int, input().split())))\n(N,M) = map(int, input().split())\nX = map(int, input().split())\nX = sorted(X)\n\nY = []\nfor i in range(1,M):\n Y.append((i,X[i] - X[i-1]))\n\nY = sorted(Y, key=lambda x: (x[1]))\nY.reverse()\n\nZ = []\nlast = 0\nfor i in range(0,min(N-1, len(Y))):\n Z.append(X[last:Y[i][0]])\n last = Y[i][0]\nif len(Z) == 0:\n Z.append(X)\n\ns = 0\nfor array in Z:\n u = max(array)\n l = min(array)\n s += u - l\n\nprint(s)', 'import numpy as np\n#from numba import njit\n\n\n#A = np.array(list(map(int, input().split())))\n(N,M) = map(int, input().split())\nX = map(int, input().split())\nX = sorted(X)\n\nY = []\nfor i in range(1,M):\n Y.append((i,X[i] - X[i-1]))\n\nY = sorted(Y, key=lambda x: (x[1]))\nY.reverse()\n\nI = list(map(lambda x: x[0], Y[0:min(N-1, len(Y))]))\nI.sort()\n\nZ = []\nlast = 0\nfor i in range(0,min(N-1, len(Y))):\n if last < I[i]:\n Z.append(X[last:I[i]])\n last = I[i]\nZ.append(X[last:])\nif len(Z) == 0:\n Z.append(X)\n\ns = 0\nfor array in Z:\n if len(array) > 0:\n u = max(array)\n l = min(array)\n s += u - l\n\nprint(s)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s184367412', 's514754151', 's665844289']
[42948.0, 61276.0, 51104.0]
[292.0, 363.0, 324.0]
[646, 534, 673]
p03137
u223904637
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m=map(int,input().split())\nx=list(map(int,input().split()))\n\nx.sort()\n\nif n>=m:\n print(0)\n exit()\nsa=[]\nfor i in range(m-1):\n sa.append(x[i+1]-x[i])\nsa.sort()\nans=x[-1]-x[0]\nfor i in range(n-1):\n ans-=sa[i]\nprint(ans)', 'n,m=map(int,input().split())\nx=list(map(int,input().split()))\n\nx.sort()\n\nif n>=m:\n print(0)\n exit()\nsa=[]\nfor i in range(m-1):\n sa.append(x[i+1]-x[i])\nsa.sort(reverse=True)\nans=x[-1]-x[0]\nfor i in range(n-1):\n ans-=sa[i]\nprint(ans)']
['Wrong Answer', 'Accepted']
['s170928584', 's477138185']
[13968.0, 13960.0]
[121.0, 124.0]
[231, 243]
p03137
u227082700
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m=map(int,input().split())\nx=list(map(int,input().split()))\nx.sort()\na=[x[i+1]-x[i]for i in range(m-1)]\nif m<=n:print(0);exit()\na.sort()\nprint(sum(a[:m-n+1]))', 'n,m=map(int,input().split())\nx=list(map(int,input().split()))\nx.sort()\na=[x[i+1]-x[i]for i in range(m-1)]\nif m<=n:print(0);exit()\na.sort()\nprint(sum(a[:m-n]))']
['Wrong Answer', 'Accepted']
['s583536583', 's243390837']
[13960.0, 13968.0]
[100.0, 99.0]
[160, 158]
p03137
u249727132
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N, M = map(int, input().split())\nX = list(map(int, input().split()))\nX = list(set(X))\nX.sort()\nM = len(X)\nL = [X[i + 1] - X[i] for i in range(M - 1)]\nL.sort()\nif N >= M:\n print("0")\nelse:\n print(L)\n print(sum(L[:M - N]))', 'N, M = map(int,input().split())\nX = list(map(int,input().split()))\nX = list(set(X))\nX.sort()\nM = len(X)\nL = [X[i + 1] - X[i] for i in range(M - 1)]\nL.sort()\nif N >= M:\n print("0")\nelse:\n print(L)\n print(sum(L[:M - N]))', 'N, M = map(int, input().split())\nX = list(map(int, input().split()))\nX = list(set(X))\nX.sort()\nM = len(X)\nL = [X[i + 1] - X[i] for i in range(len(X) - 1)]\nL.sort()\nif N >= M:\n print("0")\nelse:\n print(sum(L[:M - N]))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s191260138', 's404121597', 's294586504']
[14672.0, 14716.0, 14712.0]
[84.0, 95.0, 85.0]
[229, 227, 221]
p03137
u250102437
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['# -*- coding: utf-8 -*-\n\n\nfrom sys import stdin\n\n\n############################################\n#from sys import stdin\nimport numpy as np\n\n# read data for n sequences.\ninput = stdin.readline().split()\nm = int(input[0])\nn = int(input[1])\n#n = int(stdin.readline().split()[1])\ndata = np.zeros(n)\nd = stdin.readline().split()\nfor i,x in enumerate(d):\n data[i] = int(x)\ndata = sorted(data)\n\ndif = np.zeros(len(data)-1)\nfor x in range(0, len(data)-1):\n dif[x] = data[x+1]-data[x]\n\nout = 0\n\n# split in m data.\n#print(data)\ndif = np.zeros(len(data)-1)\nfor x in range(0, len(data)-1):\n dif[x] = data[x+1]-data[x]\nmaxdif = sorted(dif, reverse=True)[:m-1]\nindex=[]\nfor i, x in enumerate(dif):\n if x in maxdif: \n index.append(i)\n\n\nfor i,x in enumerate(index):\n if not x == 0:\n if i==0:\n out += np.sum(data[:x])\n elif x==len(data):\n None\n else:\n out += np.abs(data[x]-data[index[i-1]+1])\n\nprint(out)\n \n \n\n \n\n#print(data)\n\n \n\n\ntopdif = sorted(dif, reverse=True)[:m]\ntopkey=[]\nfor i,x in enumerate(dif):\n if x in topdif:\n topkey.append(i)\n', 'from sys import stdin\n\n\n\n############################################\n#from sys import stdin\nimport numpy as np\n\n# read data for n sequences.\ninput = stdin.readline().split()\nm = int(input[0])\nn = int(input[1])\n#n = int(stdin.readline().split()[1])\ndata = np.zeros(n)\nd = stdin.readline().split()\nfor i,x in enumerate(d):\n data[i] = int(x)\ndata = sorted(data)\n\ndif = np.zeros(len(data)-1)\nfor x in range(0, len(data)-1):\n dif[x] = data[x+1]-data[x]\n\nout = 0\n\n# split in m data.\n#print(data)\ndif = np.zeros(len(data)-1)\nfor x in range(0, len(data)-1):\n dif[x] = data[x+1]-data[x]\nout = sum(sorted(dif, reverse=True)[m-1:])\n\n \n\nprint(int(out))\n ']
['Wrong Answer', 'Accepted']
['s812051528', 's236788810']
[27624.0, 27104.0]
[2112.0, 470.0]
[1166, 674]
p03137
u251123951
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N, M= map(int, input().split())\nzahyo = []\nfor i in map(int,input().split()):\n zahyo += [i]\nsum=0\n\n\ndef merge(p,q):\n result=[]\n i,j=0,0\n \n while i<len(p) and j<len(q):\n \n \n if p[i] <= q[j]:\n result.append(p[i])\n i+=1\n else:\n result.append(q[j])\n j+=1\n\n \n \n \n if i<len(p):\n result.extend(p[i:])\n if j<len(q):\n result.extend(q[j:])\n \n return result\n\n\ndef mergesort(a):\n \n if len(a)==1:\n return a\n \n p=mergesort(a[:len(a)//2])\n \n q=mergesort(a[len(a)//2:])\n \n return merge(p,q)\n\nmergesort(zahyo)\ngap = []\nfor i in range(M-1):\n gap += [zahyo[i+1]-zahyo[i]] \nmergesort(gap)\nif N >= M:\n print(0)\nelif N == 1:\n print(zahyo[M-1] - zahyo[0])\nelse:\n for i in gap[N-1:]:\n sum += i\n print(sum)', 'N, M= map(int, input().split())\nzahyo = []\nfor i in map(int,input().split()):\n zahyo += [i]\nsum=0\n\n\ndef merge(p,q):\n result=[]\n i,j=0,0\n \n while i<len(p) and j<len(q):\n \n \n if p[i] <= q[j]:\n result.append(p[i])\n i+=1\n else:\n result.append(q[j])\n j+=1\n\n \n \n \n if i<len(p):\n result.extend(p[i:])\n if j<len(q):\n result.extend(q[j:])\n \n return result\n\n\ndef mergesort(a):\n \n if len(a)==1:\n return a\n \n p=mergesort(a[:len(a)//2])\n \n q=mergesort(a[len(a)//2:])\n \n return merge(p,q)\n\nif M==1:\n print(0)\nelse:\n zahyo = mergesort(zahyo)\n gap = []\n for i in range(M-1):\n gap += [zahyo[i+1]-zahyo[i]] \n gap = mergesort(gap)\n if N >= M:\n print(0)\n else:\n for i in gap[:M-N]:\n sum += i\n print(sum)']
['Runtime Error', 'Accepted']
['s146048491', 's986766126']
[13832.0, 13832.0]
[1307.0, 1189.0]
[1774, 1814]
p03137
u252828980
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m = map(int,input().split())\nw = list(map(int,input().split()))\nw.sort()\nli = []\nfor i in range(len(w)-1):\n a = w[i+1]-w[i]\n li.append(a)\nli.sort(reverse = True)\n\n\nb = sum(li[:(n-1)])\nd = abs(max(w)) + abs(min(w))\n\nprint(d-b)', 'n,m = map(int,input().split())\nli = list(map(int,input().split()))\nli2 = []\nli.sort()\nfor i in range(m-1):\n li2.append(abs(li[i]-li[i+1]))\nli2.sort()\n\nif n >= m:\n print(0)\nelse:\n print(sum(li2[0:m-n]))']
['Wrong Answer', 'Accepted']
['s941248794', 's020792786']
[13968.0, 13960.0]
[122.0, 115.0]
[233, 210]
p03137
u254871849
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['# 2019-11-12 13:20:54(JST)\nimport sys\n# import collections\n# import math\n# from string import ascii_lowercase, ascii_uppercase, digits\nfrom bisect import bisect_left as bi_l, bisect_right as bi_r\n# import itertools\n# from functools import reduce\n# import operator as op\n# from scipy.misc import comb # float\n# import numpy as np \n\ndef main():\n n, m, *x = (int(i) for i in sys.stdin.read().split())\n x.sort()\n if n >= m:\n print(0)\n sys.exit()\n\n ran = x[-1] - x[0] + 1\n quotient, remainder = ran // n, ran % n\n total_count = 0\n for i in range(x[0], x[-1-remainder], quotient):\n print(i)\n current = [j for j in x if i <= j < i + quotient]\n if not current:\n total_count -= 1\n continue\n count = max(current) - min(current)\n total_count += count\n \n total_count += remainder\n print(total_count)\n\n\n\nif __name__ == "__main__":\n main()\n', "import sys\nimport numpy as np \n\nn, m = map(int, sys.stdin.readline().split())\nx = np.array(sys.stdin.readline().split(), dtype=np.int64)\nx.sort()\n\ndef main():\n d = np.sort(x[1:] - x[:-1])[::-1]\n d = np.concatenate((np.array([0]), np.cumsum(d)))\n res = d[m-1] - d[min(n, m) - 1]\n print(res)\n\nif __name__ == '__main__':\n main()"]
['Wrong Answer', 'Accepted']
['s359589301', 's012911359']
[13964.0, 22160.0]
[2104.0, 183.0]
[930, 341]
p03137
u255943004
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M = map(int,input().split())\nX = sorted([int(i) for i in input().split()])\n\nD = sorted([X[i]-X[i+1] for i in range(M-1)])\nprint(sum(D[:M-N]))\n \n', 'N,M = map(int,input().split())\nX = sorted([int(i) for i in input().split()])\nD = sorted([X[i]-X[i+1] for i in range(M-1)])\nprint(sum(D[:M-N])) if M > N else print(0)\n \n', 'N,M = map(int,input().split())\nX = sorted([int(i) for i in input().split()])\nD = sorted([X[i+1]-X[i] for i in range(M-1)])\nprint(sum(D[:M-N])) if M > N else print(0)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s270377356', 's329963820', 's821751500']
[13840.0, 13840.0, 13840.0]
[106.0, 109.0, 109.0]
[149, 171, 166]
p03137
u266569040
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['import sys\n\nn,m=input().split()\nN = int(n)\nM = int(m)\nX = input().split()\n\nX = [int(x) for x in X]\n\nX.sort()\nif M == 1:\n print(0)\n sys.exit()\nelif M < 1:\n sys.exit()\n\nminus = [X[i]-X[i-1] for i in range(1,M)]\n#print(minus)\n\nminus.sort()\n#print(minus)\nsum_num = 0\nif N < M:\n for i in range(N+1):\n sum_num += minus[i]\n print(sum_num)\nelif N >= M:\n print(0):', 'import sys\n\nn,m=input().split()\nN = int(n)\nM = int(m)\nX = input().split()\n\nX = [int(x) for x in X]\n\nX.sort()\nif M == 1:\n print(0)\n sys.exit()\nelif M < 1:\n sys.exit()\n\nminus = [X[i]-X[i-1] for i in range(1,M)]\n#print(minus)\n\nminus.sort()\n#print(minus)\nsum_num = 0\nif N < M:\n for i in range(N+1):\n sum_num += minus[i]\n print(sum_num)\nelif N >= M:\n print(0): ', 'import sys\n\nn,m=input().split()\nN = int(n)\nM = int(m)\nX = input().split()\n\nX = [int(x) for x in X]\n\nX.sort()\nif M == 1:\n print(0)\n sys.exit()\nelif M < 1:\n sys.exit()\n\nminus = [X[i]-X[i-1] for i in range(1,M)]\n#print(minus)\n\nminus.sort()\n#print(minus)\nsum_num = 0\nif N < M:\n for i in range(M-N):\n sum_num += minus[i]\n print(sum_num)\nelif N >= M:\n print(0)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s474459181', 's983818732', 's909914685']
[3064.0, 3064.0, 13832.0]
[17.0, 17.0, 108.0]
[401, 405, 401]
p03137
u273928723
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['a=input()\nb=input()\nc=a.split()\nn=int(c[0])\nd=b.split()\nd=[int(i) for i in d]\nd.sort(reverse=True)\ncount=0\nll=list()\nfor i in d:\n if count!=0:\n ll.append(c-i)\n c=i\n count+=1\nll.sort()\nfor i in range(n-1):\n ccc=len(ll)\n if ccc>=1\n del ll[-1]\nprint(sum(ll))\n', 'a=input()\nb=input()\nc=a.split()\nn=int(c[0])\nd=b.split()\nd=[int(i) for i in d]\nd.sort(reverse=True)\ncount=0\nll=list()\nfor i in d:\n if count!=0:\n ll.append(c-i)\n c=i\n count+=1\nll.sort()\nfor i in range(n-1):\n ccc=len(ll)\n if ccc>=1:\n del ll[-1]\nprint(sum(ll))\n']
['Runtime Error', 'Accepted']
['s691490648', 's798789611']
[3064.0, 14468.0]
[17.0, 146.0]
[285, 286]
p03137
u276204978
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['if M <= N:\n print(0)\nelse:\n X.sort()\n L = []\n for i in range(M-1):\n L.append(X[i+1] - X[i])\n L.sort(reverse=True)\n print(X[-1]-X[0]-sum(L[:N-1]))', 'N, M = map(int, input().split())\nX = list(map(int, input().split()))\n\nif M <= N:\n print(0)\nelse:\n X.sort()\n L = []\n for i in range(M-1):\n L.append(X[i+1] - X[i])\n L.sort(reverse=True)\n print(X[-1]-X[0]-sum(L[:N-1]))']
['Runtime Error', 'Accepted']
['s817026149', 's200163715']
[3064.0, 13968.0]
[18.0, 111.0]
[170, 240]
p03137
u279136325
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['import sys\n\nN, M = [int(x) for x in input().split()]\nnums = [int(x) for x in input().split()]\n\nif not nums:\n print(0)\n sys.exit()\n\nif N >= M:\n print(0)\n sys.exit()\n\nmem = {}\nnums.sort()\n\nprint(0)', '\nimport sys\n\nN, M = [int(x) for x in input().split()]\nnums = list(set([int(x) for x in input().split()]))\n\nif not nums:\n print(0)\n sys.exit()\n\nif N >= M:\n print(0)\n sys.exit()\n\nnums.sort()\n\nrank = [(abs(nums[i] - nums[i-1]), (i-1, i)) for i in range(1, len(nums))]\nrank = sorted(rank, reverse=True)[:N-1]\n\npos = [0] + [pos[1] for dis, pos in rank]\npos.sort()\nans = 0\nfor i in range(len(pos)):\n if i == len(pos)-1:\n ans += abs(nums[pos[i]] - nums[-1])\n else:\n ans += abs(nums[pos[i]] - nums[pos[i+1]-1])\n\nprint(ans)\n\n\n']
['Wrong Answer', 'Accepted']
['s051764479', 's390905241']
[13840.0, 28128.0]
[81.0, 221.0]
[207, 549]
p03137
u282228874
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m = map(int,input().split())\nX = list(map(int,input().split()))\nX.sort()\np = []\nfor i in range(1,m):\n p.append(X[i]-X[i-1])\np.sort()\nprint(sum(p[:m-n-1]))', 'N,M = map(int,input().split())\nX = list(map(int,input().split()))\nX.sort()\ndistance = []\nfor i in range(1,M):\n distance.append(X[i]-X[i-1])\ndistance.sort(reverse = 1)\nprint(sum(distance[N-1:]))']
['Wrong Answer', 'Accepted']
['s941507694', 's128353036']
[13968.0, 13960.0]
[114.0, 113.0]
[159, 196]
p03137
u284363684
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['# input\nN, M = map(int, input().split()) \nX = list(map(int, input().split()))\n\nX.sort()\nK = [\n abs(X[i] - X[i - 1])\n for i in range(1, N)\n]\n\nprint(sum(K[:M - (N - 1)])', '# input\nN, M = int(input())\nX = list(map(int, input().split()))\n\nX.sort()\nK = [\n abs(X[i] - X[i - 1])\n for i in range(1, N)\n]\n\nprint(sum(K[:M - (N - 1)]))', '# input\nN, M = int(input())\nX = list(map(int, input().split()))\n\nX.sort()\nK = [\n abs(X[i] - X[i - 1])\n for i in range(1, N)\n]\n\nprint(sum(K[:M - (N - 1)]))', '# input\nN, M = map(int, input().split())\nX = list(map(int, input().split()))\n\nX.sort()\nK = sorted(\n [\n abs(X[i] - X[i - 1])\n for i in range(1, M)\n ]\n)\n\nprint(K)\n\nprint(sum(K[:M - (N - 1)]))', '# input\nN, M = map(int, input().split())\nX = list(map(int, input().split()))\n\nX.sort()\nK = sorted(\n [\n abs(X[i] - X[i - 1])\n for i in range(1, M)\n ],\n reverse=True\n)\n\nprint(K)\n\nprint(sum(K[N - 1:]))\n', '# input\nN, M = int(input())\nX = list(map(int, input().split()))\n\nX.sort()\nK = [\n abs(X[n] - X[n - 1])\n for i in range(1, N)\n]\n\nprint(sum(K[:M - (N - 1)]))\n', '# input\nN, M = map(int, input().split())\nX = list(map(int, input().split()))\n\nX.sort()\nK = sorted(\n [\n abs(X[i] - X[i - 1])\n for i in range(1, M)\n ],\n reverse=True\n)\n\nprint(sum(K[N - 1:]))']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s182771149', 's275745170', 's327265107', 's461059659', 's534199166', 's784075643', 's789820480']
[2940.0, 3060.0, 3060.0, 13960.0, 13968.0, 3060.0, 13968.0]
[17.0, 17.0, 17.0, 113.0, 112.0, 18.0, 105.0]
[173, 160, 160, 209, 222, 161, 211]
p03137
u296783581
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M = map(int,(input().split()))\nX = list(map(int,(input().split())))\nX.sort()\nif M > N:\n dist = [X[i+1]-X[i] for i in range(M - 1)]\n dist.sort(reverse = True)\n del dist[0:N]\n print(sum(dist))\nelse:\n print(0)', 'N,M = map(int,(input().split()))\nX = list(map(int,(input().split())))\nX.sort()\nif M > M:\n dist = [X[i+1]-X[i] for i in range(M - 1)]\n dist.sort(reverse = True)\n for i in range(N - 1):\n del dist[0]\n print(sum(dist))\nelse:\n print(0)', 'N,M = map(int,(input().split()))\nX = list(map(int,(input().split())))\nX.sort()\nif M > N:\n dist = [X[i+1]-X[i] for i in range(M - 1)]\n dist.sort(reverse = True)\n del dist[0:N]\n print(sum(dist))\nelse:\n print(0)', 'N,M = map(int,(input().split()))\nX = list(map(int,(input().split())))\nX.sort()\nif M > N:\n dist = [X[i+1]-X[i] for i in range(M - 1)]\n dist.sort(reverse = True)\n del dist[0:N-1]\n print(sum(dist))\nelse:\n print(0)']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s066997790', 's781171775', 's804896460', 's025338416']
[2940.0, 13968.0, 13960.0, 13960.0]
[17.0, 78.0, 106.0, 102.0]
[224, 249, 220, 222]
p03137
u304593245
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['\n\nN,M = list(map(int, input().split()))\nX = list(map(int, input().split()))\n\nX.sort()\ncnt = 0\narr = [0]*(M-1)\nif N > M:\n ans = 0\nelse:\n for i in range(1,M):\n arr[i] = (abs(X[i-1]-X[i]))\n #print(arr)\n arr.sort()\n ans = sum(arr[0:M-N])\nprint(ans)', '\n\nN,M = list(map(int, input().split()))\nX = list(map(int, input().split()))\n\nX.sort()\ncnt = 0\narr = [0]*(M-1)\nif N >= M:\n ans = 0\nelse:\n for i in range(1,M):\n arr[i-1] = (abs(X[i-1]-X[i]))\n #print(arr)\n arr.sort()\n ans = sum(arr[0:M-N])\nprint(ans)']
['Runtime Error', 'Accepted']
['s272295403', 's297755024']
[20552.0, 20232.0]
[91.0, 100.0]
[266, 269]
p03137
u305965165
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['\nn, m = (int(i) for i in input().split()) \nx = [int(i) for i in input().split()] \n\nif m > 1:\n x_diff = []\n for i in range(m-1):\n x_diff.append(x[i+1] - x[i])\nelse:\n x_diff = [0]\n\nfor i in range(n-1):\n max_num = max(x_diff)\n max_index = x_diff.index(max_num)\n x_diff[max_index] = 0\n\nprint(sum(x_diff))', 'n, m = (int(i) for i in input().split()) \nx = [int(i) for i in input().split()] \n\nx_diff = []\nfor i in range(m-1):\n x_diff.append(x[i+1] - x[i])\n\nfor i in range(n-1):\n max_num = max(x_diff)\n max_index = x_diff.index(max_num)\n x_diff[max_index] = 0\n\nprint(sum(x_diff))', 'n, m = (int(i) for i in input().split()) \nx = sorted([int(i) for i in input().split()])\n\nif m > 1:\n x_diff = []\n for i in range(m-1):\n x_diff.append(x[i+1] - x[i])\nelse:\n x_diff = [0]\n\nif n > 1:\n x_diff = sorted(x_diff)[:-(n-1)]\n\nprint(sum(x_diff))']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s271799305', 's444504625', 's547956473']
[13840.0, 13840.0, 13832.0]
[2105.0, 2104.0, 119.0]
[327, 281, 268]
p03137
u309039873
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M = map(int,input().split())\nXs = list(map(int,input().split()))\nif len(Xs) <= N:\n print(0)\nelse:\n Xs.sort()\n Xdivs = []\n for i in range(M-1):\n Xdivs.append(Xs[i+1]-Xs[i])\n Xdivs.sort()\n print(sum(Xdivs[0:M-N+1]))', 'N,M = map(int,input().split())\nXs = list(map(int,input().split()))\nif len(Xs) <= N:\n print(0)\nelse:\n Xs.sort()\n Xdivs = []\n for i in range(M-1):\n Xdivs.append(Xs[i+1]-Xs[i])\n Xdivs.sort()\n print(sum(Xdivs[:M-N+1]))', 'N,M = map(int,input().split())\nXs = list(map(int,input().split()))\nif len(Xs) <= N:\n print(0)\nelse:\n Xs.sort()\n Xdivs = []\n for i in range(M-1):\n Xdivs.append(Xs[i+1]-Xs[i])\n Xdivs.sort()\n print(sum(Xdivs[:M-N]))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s073868951', 's764464649', 's633782576']
[13960.0, 13964.0, 13968.0]
[110.0, 116.0, 110.0]
[240, 239, 237]
p03137
u310233294
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N, M = map(int, input().split())\nX = list(map(int, input().split()))\nX.sort()\nx = []\nfor i in range(M - 1):\n x += [X[i + 1] - X[i]]\nx.sort()\nans = sum(x[:M-N])\nprint(x)', 'N, M = map(int, input().split())\nX = list(map(int, input().split()))\nX.sort()\nx = []\nif N >= M:\n ans = 0\nelse:\n for i in range(M - 1):\n x += [X[i + 1] - X[i]]\n x.sort()\n ans = sum(x[:M-N])\nprint(ans)']
['Wrong Answer', 'Accepted']
['s657332251', 's997827929']
[13968.0, 13968.0]
[130.0, 123.0]
[171, 218]
p03137
u312078744
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
["n, m = map(int, input().split())\nx = list(map(int, input().split()))\n\nxSort = sorted(x)\n\ndif = [0] * (m - 1)\nfor i in range(m - 1):\n dif[i] = xSort[i + 1] - xSort[i]\nans = sum(dif)\n\nif (n == 1 or m == 1):\n print(ans)\nelse:\n tar = len(dif) - n\n difSort = sorted(dif)\n difS_2 = difSort[:tar]\n ans = sum(difS_2)\n print(ans)\n''' \n for j in range(n - 1):\n tar = j + 1\n tarInd = tar * -1\n tarVal = sorted(dif)[tarInd]\n ans -= tarVal\n'''\n# print(ans)\n# >>>TLE\n#\n\n\n\n'''\n import numpy as np\n difArray = np.array(dif)\n difIndex = difArray.argsort()\n\n for i in range(n - 1):\n tar = m - i\n maxIndex = difIndex[tar]\n maxVal = diff\n'''\n", "n, m = map(int, input().split())\nx = list(map(int, input().split()))\n\nxSort = sorted(x)\n\ndif = [0] * (m - 1)\nfor i in range(m - 1):\n dif[i] = xSort[i + 1] - xSort[i]\nans = sum(dif)\n\nif (n == 1 or m == 1):\n print(ans)\n\nelif (n >= m):\n print('0')\nelse:\n tar = len(dif) - n + 1\n difSort = sorted(dif)\n difS_2 = difSort[:tar]\n ans = sum(difS_2)\n print(ans)\n''' \n for j in range(n - 1):\n tar = j + 1\n tarInd = tar * -1\n tarVal = sorted(dif)[tarInd]\n ans -= tarVal\n'''\n# print(ans)\n# >>>TLE\n#\n\n\n\n'''\n import numpy as np\n difArray = np.array(dif)\n difIndex = difArray.argsort()\n\n for i in range(n - 1):\n tar = m - i\n maxIndex = difIndex[tar]\n maxVal = diff\n'''\n"]
['Wrong Answer', 'Accepted']
['s811414343', 's152434357']
[13968.0, 13968.0]
[115.0, 115.0]
[785, 820]
p03137
u319245933
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M,*X = map(int, open(0).read().split())\nX.sort()\nD = [abs(X[i+1] - X[i]) for i in range(M-1)]\nif N >= M:\n print(X[-1] - X[0] - sum(sorted(D)[-(N-1):][::-1]))\nelse:\n print(0)', 'import sys\n \n\n\n \nN,M,*X = map(int, open(0).read().split())\n \n\n\nif N >= M:\n print(0)\n sys.exit()\n \nX.sort()\nans = []\nfor i in range(M-1):\n ans.append(abs(X[i+1] - X[i]))\n \nans.sort()\nprint(X[-1] - X[0] - sum(ans[:N-1:-1]))', 'import sys\n\n\n\n\n# N,M,*X = map(int, open(0).read().split())\n\n\n\nif N >= M:\n print(0)\n sys.exit()\n\nX.sort()\nans = []\nfor i in range(M-1):\n ans.append(abs(X[i+1] - X[i]))\n\nprint(X[-1] - X[0] - sum(sorted(ans)[::-1][:N-1]))', 'N,M,*X=map(int,open(0).read().split());X.sort();print(0if N>=M else sum(sorted(abs(X[i+1]-X[i])for i in range(M-1))[:M-N]))']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s386982885', 's664392692', 's768180103', 's959926308']
[20632.0, 19832.0, 8916.0, 19972.0]
[84.0, 93.0, 28.0, 82.0]
[181, 388, 385, 123]
p03137
u324314500
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
["import sys\n\ns2nn = lambda s: [int(c) for c in s.split(' ')]\nss2nn = lambda ss: [int(s) for s in list(ss)]\nss2nnn = lambda ss: [s2nn(s) for s in list(ss)]\ni2s = lambda: sys.stdin.readline().rstrip()\ni2n = lambda: int(i2s())\ni2nn = lambda: s2nn(i2s())\nii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]\n\n\n\ndef main(N, M, Xm):\n \n if N >= M:\n print(0)\n return\n \n Xm.sort()\n \n if N == 1:\n d = Xm[M-1] - Xm[0]\n print(d)\n return\n \n \n Dm = [Xm[i] - Xm[i-1] for i in range(1, M)]\n \n Dm.sort()\n print(Dm)\n \n \n \n \n \n \n d = 0\n for i in range(M-N):\n d += Dm[i]\n print(d)\n\nN, M = i2nn()\nXm = i2nn()\nmain(N, M, Xm)\n\n\n", "import sys\n\ns2nn = lambda s: [int(c) for c in s.split(' ')]\nss2nn = lambda ss: [int(s) for s in list(ss)]\nss2nnn = lambda ss: [s2nn(s) for s in list(ss)]\ni2s = lambda: sys.stdin.readline().rstrip()\ni2n = lambda: int(i2s())\ni2nn = lambda: s2nn(i2s())\nii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]\n\n\n\ndef main(N, M, Xm):\n \n if N >= M:\n print(0)\n return\n \n Xm.sort()\n \n if N == 1:\n d = Xm[M-1] - Xm[0]\n print(d)\n return\n \n \n Dm = [Xm[i] - Xm[i-1] for i in range(1, M)]\n \n Dm.sort()\n \n \n \n \n \n \n d = 0\n for i in range(M-N):\n d += Dm[i]\n print(d)\n\nN, M = i2nn()\nXm = i2nn()\nmain(N, M, Xm)\n\n\n"]
['Wrong Answer', 'Accepted']
['s702158052', 's218784747']
[14964.0, 14972.0]
[111.0, 105.0]
[1587, 1573]
p03137
u329036729
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n, m = list(map(int, input().split()))\nX = list(map(int, input().split()))\nX.sort()\nprint(X)\nsub = [0 for i in range(m)]\nfor i in range(m):\n if i == m-1:\n sub[i]=0\n else:\n sub[i] = X[i+1]-X[i]\nprint(sub)\n\nans = sum(sorted(sub)[:m-n+1])\nif n>= m:\n ans = 0\nprint(ans)\n# print("slip list is ", skip_list)\n# print("sub List is ", sub)', 'n, m = list(map(int, input().split()))\nX = list(map(int, input().split()))\nX.sort()\n# print(X)\nsub = [0 for i in range(m)]\nfor i in range(m):\n if i == m-1:\n sub[i]=0\n else:\n sub[i] = X[i+1]-X[i]\n# print(sub)\n\nans = sum(sorted(sub)[:m-n+1])\nif n>= m:\n ans = 0\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s784656441', 's680937741']
[13968.0, 13968.0]
[138.0, 121.0]
[353, 293]
p03137
u329407311
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M = map(int,input().split())\n\nList = list(map(int,input().split()))\nList.sort()\n\nsa = []\n\nfor i in range(M-1):\n a = List[i+1] - List[i]\n sa.append(a)\n \nsa.sort()\n\nprint(sum(sa[N-1:]))', 'N,M = map(int,input().split())\n\nList = list(map(int,input().split()))\nList.sort()\n\nsa = []\n\nfor i in range(M-1):\n a = List[i+1] - List[i]\n sa.append(a)\n \nsa.sort()\nl = len(sa)\n\nif N >= M:\n print(0)\nelse:\n print(sum(sa[:l-N+1]))\n']
['Wrong Answer', 'Accepted']
['s685658298', 's673167372']
[13968.0, 13968.0]
[113.0, 116.0]
[188, 233]
p03137
u333190709
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
[' N, M = [int(n) for n in input().split()]\n X = sorted([int(n) for n in input().split()])\n\n if N >= M:\n print(0)\n else:\n diff = []\n for i in range(len(X) - 1):\n diff.append(X[i+1] - X[i])\n\n diff = list(reversed(sorted(diff)))\n s = 0\n\n for i in range(N - 1):\n s += diff[i]\n answer = X[-1] - X[0] - s\n print(answer)', 'N, M = [int(n) for n in input().split()]\nX = sorted([int(n) for n in input().split()])\n\nanswer = 0\n\nif N >= M:\n pass\nelse:\n diff = []\n for i in range(len(X) - 1):\n diff.append(X[i+1] - X[i])\n\n diff = list(reversed(sorted(diff)))\n s = 0\n for i in range(N - 1):\n s += diff[i]\n answer = X[-1] - X[0] - s\n\nprint(answer)']
['Runtime Error', 'Accepted']
['s924064262', 's920222076']
[2940.0, 13832.0]
[17.0, 126.0]
[360, 350]
p03137
u339503988
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n, m = map(int, input().split())\nx = sorted(set(map(int, input().split())))\nt = []\nfor i, j in zip(x, x[1:]):\n t += [i - j]\nt = sorted(t, reverse=True)\nprint(sum(t[n-1:]))\n', 'n, m = map(int, input().split())\nx = sorted(set(map(int, input().split())))\nt = []\nfor i, j in zip(x, x[1:]):\n t += [abs(i - j)]\nt = sorted(t, reverse=True)\nprint(sum(t[n-1:]))\n']
['Wrong Answer', 'Accepted']
['s321260399', 's761897616']
[18960.0, 18952.0]
[89.0, 94.0]
[175, 180]
p03137
u339550873
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['#! /usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nN,M = [int(x) for x in input().split()]\nxls = [int(x) for x in input().split()]\ndls = [xls[i+1]-xls[i] for i in range(M-1)]\nif N >= M:\n ans = 0\n\n\nprint(ans)', '#! /usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nN,M = [int(x) for x in input().split()]\nxls = [int(x) for x in input().split()]\ndls = [xls[i+1]-xls[i] for i in range(M-1)]\nif N >= M:\n ans = 0\nelse:\n dls.sort()\n ans = sum(dls[0:M-N])\n\nprint(ans)', '#! /usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nN,M = [int(x) for x in input().split()]\nxls = [int(x) for x in input().split()]\nxls.sort()\ndls = [xls[i+1]-xls[i] for i in range(M-1)]\nif N >= M:\n ans = 0\nelse:\n dls.sort()\n ans = sum(dls[0:M-N])\n\nprint(ans)']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s206293631', 's613921537', 's064951773']
[13840.0, 13840.0, 13840.0]
[63.0, 101.0, 103.0]
[208, 254, 265]
p03137
u346194435
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N, M = input().split()\nN = int(N)\nM = int(M)\n\ndef diffculc(st, ed):\n if ed < st:\n tmp = ed\n ed = st\n st = tmp\n if st < 0 and ed < 0:\n diff = abs(st - ed)\n elif -1 < st and ed < 0:\n diff = abs(ed - st)\n elif st < 0 and -1 < ed:\n diff = abs(st - ed)\n elif -1 < st and -1 < ed:\n diff = ed - st\n return diff\n\nxList = [int(x) for x in input().split()]\nsortedList = sorted(xList)\n\n\ndiffcache = {}\ndiff = 0\nfor i, x in enumerate(sortedList):\n if i == len(sortedList) - 1:\n break\n diffcache[i] = diffculc(sortedList[i+1], x)\n\nrangeset = []\ncounter = 0\nfor k, v in sorted(diffcache.items(), key=lambda x: -x[1]):\n if counter == N - 1:\n break\n diffcache.pop(k)\n counter = counter + 1\n\nresult = 0\nfor k,v in diffcache:\n result = result + v\nprint(result)', 'N, M = input().split()\nN = int(N)\nM = int(M)\n\ndef diffculc(st, ed):\n if ed < st:\n tmp = ed\n ed = st\n st = tmp\n if st < 0 and ed < 0:\n diff = abs(st - ed)\n elif -1 < st and ed < 0:\n diff = abs(ed - st)\n elif st < 0 and -1 < ed:\n diff = abs(st - ed)\n elif -1 < st and -1 < ed:\n diff = ed - st\n return diff\n\nxList = [int(x) for x in input().split()]\nsortedList = sorted(xList)\n\n\ndiffcache = {}\ndiff = 0\nfor i, x in enumerate(sortedList):\n if i == len(sortedList) - 1:\n break\n diffcache[i] = diffculc(sortedList[i+1], x)\n\nrangeset = []\ncounter = 0\nfor k, v in sorted(diffcache.items(), key=lambda x: -x[1]):\n if counter == N - 1:\n break\n diffcache.pop(k)\n counter = counter + 1\n\nresult = 0\nfor k,v in diffcache.items():\n result = result + v\nprint(result)']
['Runtime Error', 'Accepted']
['s470404768', 's958125556']
[25484.0, 25488.0]
[242.0, 241.0]
[888, 896]
p03137
u347600233
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n, m = map(int, input().split())\nx = sorted([int(i) for i in input().split()])\ndiff_x = [x[i + 1] - x[i] for i in range(m - 1)]\nif n >= m:\n print(0)\nelse:\n print((x[m - 1] - x[0]) - sum(diff_x))', 'n, m = map(int, input().split())\nx = sorted([int(i) for i in input().split()])\ndiff_x = [x[i + 1] - x[i] for i in range(m - 1)]\ndiff_x.sort(reverse=True)\nif n >= m:\n print(0)\nelse:\n print((x[m - 1] - x[0]) - sum(diff_x[0:n]))', 'n, m = map(int, input().split())\nx = sorted([int(i) for i in input().split()])\ndiff_x = [x[i + 1] - x[i] for i in range(m - 1)]\ndiff_x.sort(reverse=True)\nif n >= m:\n print(0)\nelse:\n print((x[m - 1] - x[0]) - sum(diff_x[0:n - 1]))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s453583414', 's694198442', 's587782741']
[13840.0, 13840.0, 13840.0]
[95.0, 108.0, 110.0]
[200, 231, 235]
p03137
u347640436
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['from sys import sys\nn, m, *x = map(int, stdin.read().split())\nx.sort()\ny = [x[i] - x[i - 1] for i in range(1, m)]\ny.sort()\nprint(sum(y[:-n]) if n < m else 0)\n', 'n, m = map(int, input().split())\nx = list(map(int, input().split()))\nx.sort()\ny = [x[i] - x[i - 1] for i in range(1, m)]\ny.sort()\nresult = 0\nfor i in range(n - m):\n result += y[i]\nprint(result)\n', 'from sys import stdin\nn, m, *x = map(int, stdin.read().split())\nx.sort()\ny = [x[i] - x[i - 1] for i in range(1, m)]\ny.sort()\nprint(sum(y[:-n]) if n < m else 0)\n', 'from sys import stdin\nn, m, *x = map(int, stdin.read().split())\nx.sort()\ny = [x[i] - x[i - 1] for i in range(1, m)]\ny.sort()\nprint(sum(y[:m - n]) if n < m else 0)\n']
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s257303502', 's288218706', 's715666348', 's605689875']
[2940.0, 13960.0, 13964.0, 13964.0]
[17.0, 101.0, 99.0, 99.0]
[158, 195, 160, 163]
p03137
u349365032
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N, M = (int(i) for i in input().split()) \nX = [int(i) for i in input().split()] \n\ns= 0\nif N >= M:\n print(0)\nelse\n X.sort()\n for i in range(M-1):\n lg_bw_x[i] = X[i+1] - X[i]\n for i in range(M-N-1):\n s = s+lg_bw_x[i]\n print(s)', 'N, M = (int(i) for i in input().split()) \nX = [int(i) for i in input().split()] \ns= 0\nif N >= M:\n print(0)\nelse:\n X.sort()\n for i in range(M-N-1):\n s = s+X[i]\n print(s)', 'N, M = (int(i) for i in input().split()) \nX = [int(i) for i in input().split()] \ns= 0\nif N >= M:\n print(0)\nelse\n X.sort()\n for i in range(M-N-1):\n s = s+X[i]\n print(s)', 'N, M = (int(i) for i in input().split()) \nX = [int(i) for i in input().split()] \nlg_bw_x = [] \ns= 0\nif N >= M:\n print(0)\nelse:\n X.sort()\n for i in range(M-1):\n lg_bw_x.append(X[i+1] - X[i])\n lg_bw_x.sort()\n for j in range(M-N):\n s = s+lg_bw_x[j]\n print(s)']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s131574049', 's419112894', 's835458739', 's789273152']
[2940.0, 13840.0, 2940.0, 13840.0]
[17.0, 88.0, 17.0, 120.0]
[254, 188, 187, 288]
p03137
u359856428
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
["n,m = map(int,input().split(' '))\nX = list(map(int,input().split(' ')))\nX.sort(reverse = True)\ndis = []\ndiv = 0\nfor i in range(m - 1):\n dis.append(X[i + 1] = X[i])\ndis.sort(Reverse = True)\nfor i in range(n - 1):\n div += dis[i]\nprint(sum(dis) - div)", "n,m = map(int,input().split(' '))\nif n >= m:\n print(0)\nelse:\n X = list(map(int,input().split(' ')))\n X.sort()\n dis = []\n for i in range(m - 1):\n dis.append(X[i + 1] - X[i])\n dis.sort(reverse = True)\n div = 0\n total = X[m - 1] - X[0]\n\n for i in range(n - 1):\n div += dis[i]\n print(total - div)"]
['Runtime Error', 'Accepted']
['s863293267', 's409343616']
[3064.0, 13960.0]
[18.0, 123.0]
[254, 336]
p03137
u360090862
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M=[int(i) for i in input().split()]\nX=[int(i) for i in input().split()]\nX.sort()\nrui=[]\nfor i in range(len(X)-1):\n rui.append(X[i+1]-X[i])\nrui.sort()\nprint(sum(rui[0:-(N-1)]))N,M=[int(i) for i in input().split()]\nX=[int(i) for i in input().split()]\nX.sort()\nrui=[]\nfor i in range(len(X)-1):\n rui.append(X[i+1]-X[i])\nrui.sort()\nprint(sum(rui[0:-(N-1)]))', 'N,M=[int(i) for i in input().split()]\nX=[int(i) for i in input().split()]\nX.sort()\nrui=[]\nfor i in range(len(X)-1):\n rui.append(X[i+1]-X[i])\nrui.sort()\nif N==1:\n print(sum(rui))\nif M<=N:\n print(sum(rui[0:-(N-1)]))\nelse:\n print(0)', 'N,M=[int(i) for i in input().split()]\nX=[int(i) for i in input().split()]\nX.sort()\nrui=[]\nfor i in range(len(X)-1):\n rui.append(X[i+1]-X[i])\nrui.sort()\nif N==1:\n print(sum(rui))\nelif M>=N:\n print(sum(rui[0:-(N-1)]))\nelse:\n print(0)']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s293576886', 's924193243', 's713955029']
[2940.0, 13840.0, 13832.0]
[17.0, 114.0, 115.0]
[356, 233, 235]
p03137
u366541443
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['s = list(map(int, input().split()))\nprint(s)\nt = list(map(int, input().split()))\nprint(t)\n\nif(s[0] >= s[1]):\n print(0)\nelse:\n t.sort()\n u=[]\n for i in range(s[1]-1):\n u.append(t[i+1]-t[i])\n u.sort()\n print(u) \n total=0\n for i in range(s[1]-s[0]):\n total+=u[i]\n print(total)', 's = list(map(int, input().split()))\nt = list(map(int, input().split()))\n\nif(s[0] >= s[1]):\n print(0)\nelse:\n t.sort()\n u=[]\n for i in range(s[1]-1):\n u.append(t[i+1]-t[i])\n u.sort()\n total=0\n for i in range(s[1]-s[0]):\n total+=u[i]\n print(total)']
['Wrong Answer', 'Accepted']
['s978108848', 's363929183']
[13960.0, 13960.0]
[127.0, 113.0]
[289, 258]
p03137
u367130284
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['import numpy as np\nN,M=map(int,input().split(" "))\n\nA=list(sorted(map(int,input().split(" "))))\nL=np.array([A[s]-A[s+1] for s in range(M-1)])\n\nif M<=N:\n print(0)', 'N,M=map(int,input().split(" "))\n\nA=list(map(int,input().split(" ")).sort())\nprint(A)', 'import numpy as np\nN,M=map(int,input().split(" "))\n\nA=list(sorted(map(int,input().split(" "))))\nL=np.array([A[s]-A[s+1] for s in range(M-1)])\n\nif M<=N:\n print(0)', 'N,M=map(int,input().split(" "))\n\nA=list(map(int,input().split(" ")))\nA=sorted(A)\nL=[A[s]-A[s+1] for s in range(M-1)]\n\nif M<=N:\n print(0)\nelse:\n L=sorted(L)\n print(L)\n L[0:N-1]=[0 for i in range(N-1)]\n print(abs(sum(L)))', 'from numpy import*\nn,m,*x=map(int,open(0).read().split())\nx=sorted(x)\nx=[x[i+1]-x[i]for i in range(m-1)]\nprint(int(sum(sorted(x)[::-1][n-1:])))']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s087965849', 's144079191', 's935624719', 's967999436', 's862731126']
[23072.0, 9980.0, 23076.0, 13968.0, 23004.0]
[233.0, 24.0, 228.0, 117.0, 233.0]
[201, 121, 201, 271, 143]
p03137
u371467115
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m=map(int,input().split())\nx=list(map(int,input().split()))\nn=[]\nans=0\nif n>=m:\n print(0)\nelse:\n x.sort()\n for i in range(n-1):\n n.append(x[i+1]-x[i])\n n.sort(reverse=True)\n for j in range(n-1):\n ans+=n[i]\nprint(ans)', 'n,m=map(int,input().split())\nx=list(map(int,input().split()))\nl=[]\nx.sort()\nfor i in range(1,len(x)):\n l.append(abs(x[i]-x[i-1]))\nl.sort()\nprint(sum(l)-l[-1]-l[-2])', 'n,m=map(int,input().split())\nx=list(map(int,input().split()))\nx.sort()\nn=[]\nfor i in range(1,len(x)): \n for j in range(i,len(x)):\n n.append(abs(x[0]-x[i-1])+abs(x[i]-x[j-1])+abs(x[j]-x[-1]))\nprint(min(n))', 'n,m=map(int,input().split())\nx=list(map(int,input().split()))\nx.sort()\nn=[]\nif n>m:\n print(0)\n exit()\nfor i in range(1,len(x)): \n for j in range(i,len(x)):\n n.append(abs(x[0]-x[i-1])+abs(x[i]-x[j-1])+abs(x[j]-x[-1]))\nprint(min(n))\n', 'n,m=map(int,input().split())\nx=list(map(int,input().split()))\nx.sort()\nn=[]\nif n>,:\n print(0)\n exit()\nfor i in range(1,len(x)): \n for j in range(i,len(x)):\n n.append(abs(x[0]-x[i-1])+abs(x[i]-x[j-1])+abs(x[j]-x[-1]))\nprint(min(n))\n', 'n,m=map(int,input().split())\nx=list(map(int,input().split()))\nx.sort()\nl=[]\nif n>m:\n print(0)\n exit()\nfor i in range(1,len(x)): \n for j in range(i,len(x)):\n l.append(abs(x[0]-x[i-1])+abs(x[i]-x[j-1])+abs(x[j]-x[-1]))\nprint(min(n))\n', 'n,m=map(int,input().split())\nx=list(map(int,input().split()))\nl=[]\nans=0\nif n<m:\n x.sort()\n for i in range(m-1):\n l.append(x[i+1]-x[i])\n l.sort()\n for j in range(m-n):\n ans+=l[j]\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s276038198', 's306489837', 's500389313', 's510634873', 's745953300', 's870695677', 's865618026']
[13960.0, 13960.0, 127056.0, 13960.0, 2940.0, 124072.0, 13960.0]
[43.0, 121.0, 2111.0, 75.0, 17.0, 2112.0, 117.0]
[229, 165, 209, 238, 238, 238, 199]
p03137
u371763408
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m=map(int,input().split())\nX=sorted(list(map(int,input().split())))\nans=[]\nif m<n:\n print(0)\n exit()\nfor i in range(m-1):\n ans.append(X[i+1]-X[i])\nans=sorted(ans)\nprint(ans)\nprint(sum(ans[:m-n]))', 'n,m=map(int,input().split())\nX=sorted(list(map(int,input().split())))\nans=[]\nif m<n:\n print(0)\n exit()\nfor i in range(m-1):\n ans.append(X[i+1]-X[i])\nans=sorted(ans)\nprint(sum(ans[:m-n]))']
['Wrong Answer', 'Accepted']
['s613857924', 's209983716']
[13968.0, 13960.0]
[118.0, 113.0]
[200, 189]
p03137
u372923276
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['# -*- coding: utf-8 -*-\nn,m = map(int,input().split())\nxlist = list(map(int,input().split()))\n\nxlist.sort()\nylist=[]\n\nfor i in range(1,m):\n ylist.append(xlist[i]-xlist[i-1])\n\nylist.sort()\na=0\nfor i in range(1,m-n):\n a+=ylist[i]\nprint(a)\n\n', '# -*- coding: utf-8 -*-\nn,m = map(int,input().split())\nxlist = list(map(int,input().split()))\n\nxlist.sort()\nylist=[]\n\nfor i in range(1,m):\n ylist.append(xlist[i]-xlist[i-1])\n\nylist.sort()\na=0\nfor i in range(0,m-n):\n a+=ylist[i]\nprint(a)\n\n']
['Wrong Answer', 'Accepted']
['s992798957', 's040072910']
[13960.0, 13960.0]
[117.0, 117.0]
[244, 244]
p03137
u373274281
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['import sys\nN, M = map(int, input().split())\nX = list(map(int, input().split()))\n\nif N >= M:\n print(0)\n sys.exit()\n\nX.sort() # O(MlogM)\n\n# O(M)\nD = []\nfor i in range(M-1):\n D.append(X[i+1] - X[i])\n\nD.sort() # O(MlogM)\n\nprint(sum(D[:M-N+1])) # O(M)\n', 'import sys\nn, m = map(int, input().split())\nX = list(map(int, input().split()))\nif n >= m:\n print(0)\n sys.exit()\n\nprint(X)\nX.sort()\nprint(X)\n\nL = []\nfor i in range(m-1):\n L.append(X[i+1] - X[i])\nprint(L)\nL.sort(reverse=True)\nprint(L)\nprint((X[m-1]-X[0]) - (sum(L[0:n-1])))\n', 'import sys\nN, M = map(int, input().split())\nX = list(map(int, input().split()))\n\nif N >= M:\n print(0)\n sys.exit()\n\nX.sort() # O(MlogM)\n\n# O(M)\nD = []\nfor i in range(M-1):\n D.append(X[i+1] - X[i])\n\nD.sort() # O(MlogM)\n\nprint(sum(D[:M-N+2])) # O(M)\n', 'import sys\nN, M = map(int, input().split())\nX = list(map(int, input().split()))\n\nif N >= M:\n print(0)\n sys.exit()\n\nX.sort() # O(MlogM)\n\n# O(M)\nD = []\nfor i in range(M-1):\n D.append(X[i+1] - X[i])\n\nD.sort() # O(MlogM)\n\nprint(sum(D[:M-N])) # O(M)\n']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s254544406', 's264140442', 's568612543', 's602387180']
[13968.0, 13968.0, 13960.0, 13968.0]
[111.0, 141.0, 114.0, 112.0]
[250, 276, 250, 248]
p03137
u391731808
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['X.sort()\n\nmemo = dict()\ndef get_min(n,x):\n key = str((n,x))\n tmp = memo.get(key,None)\n if tmp != None:\n return tmp\n if x == []:\n tmp = 10**8\n memo[key] = tmp\n return tmp\n elif len(x) == 1:\n memo[key] = 0\n return 0\n x0 = x[0]\n if n == 1:\n tmp = x[-1]-x0\n memo[key] = tmp\n return tmp\n tmp = min([y - x0 + get_min(n-1,x[i+1:]) for i,y in enumerate(x)])\n memo[key] = tmp\n return tmp\nif N >= M:\n print(0)\nelse:\n print(get_min(N,X))', 'N,M = map(int,input().split())\nX = sorted(list(map(int,(input().split()))))\ndif_X = sorted([X[i+1]-x for i,x in enumerate(X[:-1])])\nprint(sum(dif_X[:max(0,M-N)]))']
['Runtime Error', 'Accepted']
['s755604373', 's792013956']
[3064.0, 13960.0]
[17.0, 103.0]
[525, 162]
p03137
u393512980
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N, M = map(int, input().split())\nif N >= M:\n \tprint(0)\nelse:\n\tX = list(map(int, input().split()))\n\tX = sorted(X)\n\tL = []\n\tfor i in range(0, M-1):\n \tL.append(X[i+1] - X[i])\n\tL = sorted(L, reverse = True)\n\tS = 0\n\tfor i in range(N-1):\n \tS += L[i]\n\tres = X[M-1] - X[0] - S\n\tprint(res)', 'N, M = map(int, input().split())\nX = list(map(int, input().split()))\nif N >= M:\n print(0)\nelse:\n X = sorted(X)\n L = []\n for i in range(0, M-1):\n L.append(X[i+1] - X[i])\n L = sorted(L, reverse = True)\n S = 0\n for i in range(N-1):\n S += L[i]\n res = X[M-1] - X[0] - S\n print(res)']
['Runtime Error', 'Accepted']
['s604116750', 's065513937']
[2940.0, 13960.0]
[17.0, 124.0]
[287, 317]
p03137
u403984573
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M=map(int,input().split())\nX=[int(i) for i in input().split()]\nX.sort()\ncount=[]\nsum=0\nif n<m:\n for i in range(M):\n if i != 0:\n count.append(X[i]-get)\n sum+=count[i-1]\n get=X[i]\n count.sort(reverse=True)\n if count != []:\n for i in range(N-1):\n sum-=count[i]\nprint(sum)', 'N,M=map(int,input().split())\nX=[int(i) for i in input().split()]\nX.sort()\ncount=[]\nsum=0\nif n<=m:\n for i in range(M):\n if i != 0:\n count.append(X[i]-get)\n sum+=count[i-1]\n get=X[i]\n count.sort(reverse=True)\n if count != []:\n for i in range(N-1):\n sum-=count[i]\nprint(sum)', 'n,m = map(int,input().split())\nx = [int(i) for i in input().split()]\nx.sort()\nxx = []\nfor i in range(len(x)-1):\n xx.append(abs(x[i]-x[i+1]))\nxx.sort()\nprint(sum(xx[:-(n-1)])if n!=1 else sum(xx))\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s539434325', 's919845492', 's305616159']
[13840.0, 13840.0, 13840.0]
[80.0, 80.0, 119.0]
[297, 298, 196]
p03137
u406721804
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['try:\n N, M = map(int, input().split())\n Xi = [int(x) for x in input().split()]\n\n if N < 1 or N > 10**5:\n exit()\n if M < 1 or M > 10**5:\n exit()\n if M != len(Xi):\n exit()\n for i in Xi:\n if Xi[i] < -10**5 or Xi[i] > 10**5:\n exit()\n \nexcept ValueError:\n exit()\n\n', 'try:\n N, M = map(int, input().split())\n Xi = [int(x) for x in input().split()]\n\n if N < 1 or N > 10**5:\n exit()\n if M < 1 or M > 10**5:\n exit()\n if M != len(Xi):\n exit()\n for i in Xi:\n if i < -10**5 or i > 10**5:\n exit()\n Xi = sorted(Xi)\n\n a = []\n for i in range(M-1):\n a.append(Xi[i+1]-Xi[i])\n\n a = sorted(a, reverse=True)\n s = 0\n # print(a)\n for i in range(N-1):\n # print(a[0])\n a.pop(0)\n\n for i in a:\n s += abs(i)\n print(s)\nexcept ValueError:\n exit()\nexcept IndexError:\n print(0)\n']
['Runtime Error', 'Accepted']
['s106205750', 's150061441']
[13832.0, 13696.0]
[63.0, 1625.0]
[322, 601]
p03137
u410118019
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m = map(int,input().split())\nx = list(map(int,input().split()))\nx.sort()\ns = [0] * (m-1)\nfor i in range(m-1):\n s[i] = x[i+1] - x[i]\ns.sort(reverse=1)\nif n != 1:\n print(sum(s[:-n+1]))\nelse:\n print(sum(s))', 'n,m = map(int,input().split())\nx = list(map(int,input().split()))\nx.sort()\ns = [0] * (m-1)\nfor i in range(m-1):\n s[i] = x[i+1] - x[i]\ns.sort()\nif n != 1:\n print(sum(s[:-n+1]))\nelse:\n print(sum(s))']
['Wrong Answer', 'Accepted']
['s315336488', 's904305358']
[13968.0, 13968.0]
[110.0, 114.0]
[208, 199]
p03137
u411195488
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n, m = map(int, input().split())\nx = list(map(int, input().split()))\n\nx.sort()\n\ny = []\nfor i in range(0, m - 1):\n print(x[i+1], x[i])\n y.append(x[i + 1] - x[i])\n\ny.sort()\n\ns = sum(y[0:m - n])\nprint(s)\n', 'n, m = map(int, input().split())\nx = list(map(int, input().split()))\n\nx.sort()\n\ny = []\nfor i in range(0, m - 1):\n y.append(x[i + 1] - x[i])\n\ny.sort()\n\ns = 0\nif m > n:\n s = sum(y[0:m - n])\nprint(s)']
['Wrong Answer', 'Accepted']
['s766589135', 's761764197']
[13968.0, 13960.0]
[247.0, 113.0]
[207, 202]
p03137
u411923565
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M = map(int,input().split())\nX = list(map(int,input().split()))\nX = sorted(X,reverse = False)\n\n\nif len(X) == 1:\n print(0)\nelse:\n dist = []\n for i in range(1,M):\n dist.append(X[i]-X[i-1])\n dist = sorted(dist,reverse = False)\n print(dist)\n \n for k in range(N-1):\n dist.pop()\n if len(dist) == 0:\n break\n print(sum(dist))', '\nN,M = map(int,input().split())\nX = list(map(int,input().split()))\nX = sorted(X,reverse = False)\n\n\nif len(X) == 1:\n print(0)\nelse:\n dist = []\n for i in range(1,M):\n dist.append(X[i]-X[i-1])\n dist = sorted(dist,reverse = False)\n \n for k in range(N-1):\n dist.pop()\n if len(dist) == 0:\n break\n print(sum(dist))']
['Wrong Answer', 'Accepted']
['s956889372', 's155634107']
[20236.0, 20496.0]
[113.0, 106.0]
[450, 453]
p03137
u416522077
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['spots_and_people = input().split()\nspot_values = input().split()\n\nN_spot = int(spots_and_people[1])\nN_people = int(spots_and_people[0])\n\nspot_values = [ int(value) for value in spot_values ]\nspot_values.sort()\n\nline_length = [ spot_values[i+1] - spot_values[i] for i in range(N_spot-1) ]\nline_length.sort()\nprint(line_length)\n\nif N_spot == N_people:\n travel = 0\n \nfor i in range(N_people-1):\n line_length.pop(-1)\n \n\nprint(line_length)\n\ntravel = sum(line_length)\n\nprint(travel)', 'spots_and_people = input().split()\nspot_values = input().split()\n\nN_spot = int(spots_and_people[1])\nN_people = int(spots_and_people[0])\n\nspot_values = [ int(value) for value in spot_values ]\nspot_values.sort()\n\nline_length = [ spot_values[i+1] - spot_values[i] for i in range(N_spot-1) ]\nline_length.sort()\n\n\nif N_spot <= N_people:\n\ttravel = 0\n\nelse:\n\tfor i in range(N_people-1):\n \t\tline_length.pop(-1)\n \n\n\ttravel = sum(line_length)\n\nprint(travel)']
['Runtime Error', 'Accepted']
['s571196189', 's238802674']
[13840.0, 13840.0]
[123.0, 113.0]
[480, 449]
p03137
u416758623
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n, m = list(map(int, input().split()))\nlst = sorted(set(map(int, input().split())))\nprint(lst)\ndis = []\nfor i, j in zip(lst, lst[1:]):\n dis += [j - i]\n print(dis)\nprint(sum(sorted(dis, reverse=True)[n - 1:]))', 'n, m = list(map(int, input().split()))\nlst = sorted(set(map(int, input().split())))\n\ndis = []\nfor i, j in zip(lst, lst[1:]):\n dis += [j - i]\n \nprint(sum(sorted(dis, reverse=True)[n - 1:]))']
['Wrong Answer', 'Accepted']
['s562404502', 's159250687']
[108012.0, 18952.0]
[2104.0, 92.0]
[214, 194]
p03137
u417220101
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n, m = map(int, input().split())\nx = list(map(int, input().split()))\n\n# print(n, m, x)\n\n# #%%\n# n, m =2, 5\n# x = [10, 12, 1, 2, 14]\n\n\n#%%\nx.sort()\n\n#%%\n\n\n\n\n#%%\n\ndiff_list = []\nfor i in range(m-1):\n diff = x[i+1] - x[i]\n diff_list.append(diff)\n\n\n#%%\ndiff_list.sort()\n\n\n#%%\nprint(x[-1] - x[0] - sum(diff_list[-(n-1):])\n\n#%%\n\n\n#%%\n', 'n, m = map(int, input().split())\nx = list(map(int, input().split()))\n\n# print(n, m, x)\n\n# #%%\n# n, m =2, 5\n# x = [10, 12, 1, 2, 14]\n\n\n#%%\nx.sort()\n\n#%%\n\n\n\n\n#%%\n\ndiff_list = []\nfor i in range(m-1):\n diff = x[i+1] - x[i]\n diff_list.append(diff)\n\n\n#%%\ndiff_list.sort()\n\n\n#%%\nprint(x[-1] - x[0] - sum(diff_list[-(n-1):])\n\n#%%\n\n\n#%%\n', 'n, m = map(int, input().split())\nx = list(map(int, input().split()))\n\n# print(n, m, x)\n\n# #%%\n# n, m =2, 5\n# x = [10, 12, 1, 2, 14]\n\n\n#%%\nx.sort()\n\n#%%\n\n\n\n\n#%%\n\ndiff_list = []\nfor i in range(m-1):\n diff = x[i+1] - x[i]\n diff_list.append(diff)\n\n\n#%%\ndiff_list.sort()\n\n\n#%%\nif n-1>0:\n print(sum(diff_list[:-(n-1))])\nelse:\n print(0) \n\n#%%\n\n\n#%%\n', 'n, m = map(int, input().split())\nx = list(map(int, input().split()))\n\nprint(n, m, x)\n\n# #%%\n# n, m =2, 5\n# x = [10, 12, 1, 2, 14]\n\n\n#%%\nx.sort()\n\n#%%\nif m == n:\n print(0)\n\n\n\n#%%\n\ndiff_list = []\nfor i in range(m-1):\n diff = x[i+1] - x[i]\n diff_list.append(diff)\n\n\n#%%\ndiff_list.sort()\n\n\n#%%\nprint(sum(diff_list[:-(n-1)]))\n\n#%%\n\n\n#%%\n', 'n, m = map(int, input().split())\nx = list(map(int, input().split()))\n\n# print(n, m, x)\n\n# #%%\n# n, m =2, 5\n# x = [10, 12, 1, 2, 14]\n\n\n#%%\nx.sort()\n\n#%%\n\n\n\n\n#%%\n\ndiff_list = []\nfor i in range(m-1):\n diff = x[i+1] - x[i]\n diff_list.append(diff)\n\n\n#%%\ndiff_list.sort()\n\n\n#%%\nprint(diff_list[:-(max(0,n-1))])\n\n#%%\n\n\n#%%\n', 'n, m = map(int, input().split())\nx = list(map(int, input().split()))\n\n# print(n, m, x)\n\n# #%%\n# n, m =2, 5\n# x = [10, 12, 1, 2, 14]\n\n\n#%%\nx.sort()\n\n#%%\n\n\n\n\n#%%\n\ndiff_list = []\nfor i in range(m-1):\n diff = x[i+1] - x[i]\n diff_list.append(diff)\n\n\n#%%\ndiff_list.sort()\n\n\n#%%\nif n-1>0:\n print(sum(diff_list[:-(n-1)]))\nelse:\n print(sum(diff_list)) \n\n#%%\n\n\n#%%\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s114300120', 's597243901', 's836837578', 's862900797', 's931636988', 's706418456']
[2940.0, 2940.0, 2940.0, 13968.0, 13968.0, 13968.0]
[17.0, 18.0, 18.0, 123.0, 136.0, 117.0]
[334, 334, 357, 341, 322, 370]
p03137
u419967147
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m=input().split()\nn=int(n)\nm=int(m)\na = input().split()\nfor i in range(m):\n a[i]=int(a[i])\n \nif n>=m :\n sum=0\nelse:\n b=[]\n sum=0\n for i in range(m):\n b+=[a[i+1]-a[i]]\n b.sort().reverse()\n for i in range(N-1):\n sum+=b[i]\nprint(sum)\n ', 'n,m=input().split()\nn=int(n)\nm=int(m)\na = input().split()\nfor i in range(m):\n a[i]=int(a[i])\n \nif n>=m :\n sum=0\nelse:\n b=[]\n sum=a[m-1]-a[0]\n for i in range(m-1):\n b+=[a[i+1]-a[i]]\n b.sort()\n b.reverse()\n for i in range(n-1):\n sum-=b[i]\nprint(sum)\n \n', 'n,m=input().split()\nn=int(n)\nm=int(m)\na = input().split()\nfor i in range(m):\n a[i]=int(a[i])\n \nif n>=m :\n sum=0\nelse:\n b=[]\n sum=a[m-1]-a[0]\n for i in range(m-1):\n b+=[a[i+1]-a[i]]\n b.sort()\n b.reverse()\n for i in range(n-1):\n if b[i]>0:\n sum-=b[i]\n else:\n sum+=b[i]\nprint(sum)\n \n', 'n,m=input().split()\nn=int(n)\nm=int(m)\na = input().split()\nfor i in range(m):\n a[i]=int(a[i])\na.sort()\n \nif n>=m :\n sum=0\nelse:\n b=[]\n sum=a[m-1]-a[0]\n for i in range(m-1):\n b+=[a[i+1]-a[i]]\n b.sort()\n b.reverse()\n for i in range(n-1):\n if b[i]>0:\n sum-=b[i]\n else:\n sum+=b[i]\nprint(sum)\n \n']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s205102912', 's951881820', 's977994042', 's590873767']
[11528.0, 11528.0, 11528.0, 10256.0]
[97.0, 144.0, 142.0, 160.0]
[249, 266, 309, 318]
p03137
u427344224
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N, M = map(int, input().split())\nx_list = list(map(int, input().split()))\n\nx_list.sort()\nans = 0\n\nmargin = [0] * (M - 1)\nf = x_list[0]\nfor i in range(1, M):\n margin[i - 1] = x_list[i] - f\n f = x_list[i]\nmargin = sorted(enumerate(margin), key=lambda x: -x[1])\n\ncnt = [0]\nfor i, v in margin:\n cnt.append(i + 1)\n if len(cnt) == N:\n break\n\nstart = 0\nprev = x_list[0]\nfor i, c in enumerate(cnt[1:]):\n for j in range(start, c):\n ans += x_list[j] - prev\n prev = x_list[j]\n start = c\n prev = x_list[c]\nlast = cnt[-1]\nfor i in range(last, M):\n if i == last:\n prev = x_list[i]\n else:\n ans += x_list[i] - prev\n prev = x_list[i]\n', 'N, M = map(int, input().split())\nx_list = list(map(int, input().split()))\n\nx_list.sort()\nans = 0\n\nmargin = [0] * (M - 1)\nf = x_list[0]\nfor i in range(1, M):\n margin[i - 1] = x_list[i] - f\n f = x_list[i]\nmargin = sorted(enumerate(margin), key=lambda x: (-x[1], x[0]))\n\ncnt = [0]\nfor i, v in margin:\n cnt.append(i + 1)\n if len(cnt) == N:\n break\n\nstart = 0\nprev = x_list[0]\nfor i, c in enumerate(cnt[1:]):\n for j in range(start, c):\n ans += x_list[j] - prev\n prev = x_list[j]\n start = c\n prev = x_list[c]\nlast = cnt[-1]\nfor i in range(last, M):\n if i == last:\n prev = x_list[i]\n else:\n ans += x_list[i] - prev\n prev = x_list[i]\n', 'N, M = map(int, input().split())\nx_list = list(map(int, input().split()))\nx_list.sort()\n\nmargin = []\nprev = x_list[0]\nfor i in range(1, M):\n margin.append(x_list[i] - prev)\n prev = x_list[i]\n\nmargin.sort(reverse=True)\nprint(x_list[-1] - x_list[0] - sum(margin[:N-1]))\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s296363568', 's750196777', 's028032490']
[21960.0, 26400.0, 13968.0]
[562.0, 611.0, 116.0]
[686, 694, 274]
p03137
u434664398
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
["N, M = [int(x) for x in input().split(' ')]\nXP = [int(x) for x in input().split(' ')]\nXP.sort()\nD = [0] * (len(XP)-1)\nfor x in range(len(XP)-1):\n d = XP[x+1] - XP[x]\n D[x] = d\nD.sort()\ns = 0\nfor i in range(len(D) - N + 1):\n print(i,D[i])\n s += D[i]\nprint(s)", "N, M = [int(x) for x in input().split(' ')]\nXP = [int(x) for x in input().split(' ')]\nXP.sort()\nD = [0] * (len(XP)-1)\nfor x in range(len(XP)-1):\n d = XP[x+1] - XP[x]\n D[x] = d\nD.sort()\ns = 0\nfor i in range(len(D) - N + 1):\n s += D[i]\nprint(s)"]
['Wrong Answer', 'Accepted']
['s897294843', 's958494689']
[13832.0, 13832.0]
[217.0, 120.0]
[269, 251]
p03137
u438189153
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M=map(int,input().split())\nlst=list(map(int,input().split()))\nsort(lst)\nsum_1=sum(lst)\nD=[]\nfor i in range(1,M):\n D.append(lst[i]-lst[i-1])\nsort(D,reverse=True)\nsum_2=0\nfor i in range(N-1):\n sum_2+=D[i]\nans=0\nans=sum_1-sum_2\nprint(ans)\n', 'N,M=map(int,input().split())\nif N>M:\n print(0)\n exit()\nlst=list(map(int,input().split()))\nlst.sort()\nsum_1=max(lst)-min(lst)\nD=[]\nfor i in range(1,M):\n D.append(lst[i]-lst[i-1])\nD.sort(reverse=True)\nsum_2=0\nfor i in range(N-1):\n sum_2+=D[i]\nans=0\nans=sum_1-sum_2\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s611923459', 's597986222']
[20480.0, 20596.0]
[50.0, 108.0]
[244, 286]
p03137
u442581202
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m = map(int,input().split())\nl = [int(x) for x in input().split()]\n\nl.sort()\n\ngap = [l[i]-l[i-1] for i in range(1,len(l))]\n\ngap = gap.sort()\n\nprint(sum(gap[:-(m-1)]))', "n,m = map(int,input().split())\nl = [int(x) for x in input().split()]\n\nif(n>=m):\n print('0')\n exit(0)\nl.sort()\n \ngap = [l[i+1]-l[i] for i in range(m-1)]\n \ngap.sort()\n\nprint(sum(gap[:m-n]))\n"]
['Runtime Error', 'Accepted']
['s006269197', 's416668035']
[13840.0, 13832.0]
[109.0, 106.0]
[168, 190]
p03137
u442877951
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M = map(int,input().split())\nX = list(map(int,input().split()))\nx = []\ncount = 0\nans = 0\nX.sort()\nif N >= M:\n print(0)\nfor i in range(M-1):\n x.append(abs(X[i]-X[i+1]))\nxx = sorted(x,reverse=True)\nfor j in range(N//2):\n xx.pop(j)\nans = xx[-1] - xx[0]\nprint(ans)', 'N,M = map(int,input().split())\nX = list(map(int,input().split()))\n\nans = 0\n\nif N >= M:\n pass\nelse:\n X.sort()\n dist = []\n\n for i in range(1,M):\n dist.append(abs(X[i]-X[i-1]))\n dist = sorted(dist, reverse= True)\n\n ans = sum(dist[N-1:])\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s849685004', 's709279641']
[13968.0, 13960.0]
[858.0, 116.0]
[265, 254]
p03137
u444732068
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M = map(int,input().split())\nx = sorted(list(map(int,input().split())))\n\nif M <= N:\n\tprint(0)\n\texit()\n\t\n\ndistance = [0]*(M-1)\ndistance[0] = x[1]-x[0]\nfor i in range(0,M-1):\n\tdistance[i] = x[i+1]-x[i]\n\ndistance_sorted = sorted(distance)\nprint(distance_sorted)\nans = 0\nfor i in range(0,M-N):\n\tans += distance_sorted[i]\n\nprint(ans)\n\n\n', 'N,M = map(int,input().split())\nx = sorted(list(map(int,input().split())))\n\nif M <= N:\n\tprint(0)\n\texit()\n\t\n\ndistance = [0]*(M-1)\ndistance[0] = x[1]-x[0]\nfor i in range(0,M-1):\n\tdistance[i] = x[i+1]-x[i]\n\ndistance_sorted = sorted(distance)\nans = 0\nfor i in range(0,M-N):\n\tans += distance_sorted[i]\n\nprint(ans)\n\n\n']
['Wrong Answer', 'Accepted']
['s063214756', 's226664150']
[13968.0, 13960.0]
[124.0, 118.0]
[333, 310]
p03137
u451017206
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['print(d)\n', 'N, M = map(int, input().split())\nX = sorted([int(i) for i in input().split()])\nd = sorted([X[i] - X[i-1] for i in range(1, M)])\nans = 0\nc = 0\nfor i in d:\n if c > M - N - 1:\n break\n ans += i\n c += 1\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s281127430', 's295965360']
[2940.0, 13840.0]
[17.0, 125.0]
[9, 225]
p03137
u453623947
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m = map(int,input().split())\nif n >= m :\n print(0)\nelse:\n ls=[int(s) for s in input().split()]\n ls.sort()\n d=[ls[i+1]-ls[i] for i in range(m-1)]\n d.sort()\n print(sum(d[:n-m]))\n', 'n,m = map(int,input().split())\nif n >= m :\n print(0)\nelse:\n ls=[int(s) for s in input().split()]\n ls.sort()\n d=[ls[i+1]-ls[i] for i in range(m-1)]\n d.sort()\n print(sum(d[:m-n]))\n']
['Wrong Answer', 'Accepted']
['s600233806', 's688723768']
[19960.0, 19748.0]
[85.0, 87.0]
[184, 184]
p03137
u453642820
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M=map(int,input().split())\nX=sorted(list(map(int,input().split())))\nY=[]\nfor i in range(M-1):\n y=X[i+1]-X[i]\n Y.append(y)\ny=sorted(Y)[::-1]\nprint(sum(y[N-1]))', 'N,M=map(int,input().split())\nX=sorted(list(map(int,input().split())))\nY=[]\nfor i in range(M-1):\n y=X[i+1]-X[i]\n Y.append(y)\ny=sorted(Y)[::-1]\nprint(sum(y[N-1:]))']
['Runtime Error', 'Accepted']
['s862947694', 's301459857']
[13960.0, 13968.0]
[121.0, 117.0]
[166, 167]
p03137
u454524105
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n, m = map(int, input().split())\nx = [int(i) for i in input().split()]\nif n >= m:\n print(0)\n exit()\nx.sort()\ndis = [abs(x[i+1] - x[i]) for i in range(m-1)]\ndis.sort()\nfor _ in range(n-1): dis.pop(-1)\nprint(dis)\nprint(sum(dis))', 'n, m = map(int, input().split())\nx = [int(i) for i in input().split()]\nif n >= m:\n print(0)\n exit()\nx.sort()\ndis = [abs(x[i+1] - x[i]) for i in range(m-1)]\ndis.sort()\nfor _ in range(n-1): dis.pop(-1)\nprint(sum(dis))']
['Wrong Answer', 'Accepted']
['s886312599', 's335095354']
[13832.0, 13840.0]
[123.0, 121.0]
[232, 221]
p03137
u459150945
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n, m = map(int, input().split())\nXm = list(map(int, input().split()))\nif n >= m:\n print(0)\nelse:\n Xm.sort()\n check = [Xm[i+1] - Xm[i] for i in range(m-1)]\n check.sort(reverse=True)\n print(sum(check) - check[:n-1])\n', 'n, m = map(int, input().split())\nXm = list(map(int, input().split()))\nif n >= m:\n print(0)\nelse:\n Xm.sort()\n check = [Xm[i+1] - Xm[i] for i in range(m-1)]\n check.sort(reverse=True)\n print(sum(check) - sum(check[:n-1]))\n']
['Runtime Error', 'Accepted']
['s056411248', 's989415631']
[13960.0, 13968.0]
[101.0, 101.0]
[229, 234]
p03137
u460245024
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['import sys\n\nN, M = map(int, input().split())\n\nif N >= M:\n print(0)\n sys.exit(0)\n\nX = list(map(int, input().split()))\n', 'import sys\n\nN, M = map(int, input().split())\nX = list(map(int, input().split()))\n\nif N >= M:\n print(0)\n sys.exit(0)\n', 'import sys\n\nN, M = map(int, input().split())\nif N >= M:\n print(0)\n sys.exit(0)\n\nX = list(map(int, input().split()))\nX.sort()\n\ndistance_list = [b - a for a, b in zip(X, X[1:])]\ndistance_list.sort()\n\nif N != 1:\n print(sum(distance_list[:-N+1]))\nelse:\n print(sum(distance_list))\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s503868805', 's562176642', 's368380023']
[13960.0, 13968.0, 13968.0]
[41.0, 42.0, 97.0]
[123, 122, 288]
p03137
u466331465
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M = [int(x) for x in input().split()]\nif N>=M:\n print(0)\n exit()\nX = [int(x) for x in input().split()]\nX.sort()\nL = []\nfor i in range(M-1):\n L.append(X[i+1]-X[i])\nL.sort()\nprint(L)\nans = sum(L[:M-N])\nprint(ans)', 'N,M = [int(x) for x in input().split()]\nif N>=M:\n print(0)\n exit()\nX = [int(x) for x in input().split()]\nX.sort()\nL = []\nfor i in range(M-1):\n L.append(X[i+1]-X[i])\nL.sort()\nans = sum(L[:M-N])\nprint(ans)']
['Wrong Answer', 'Accepted']
['s703240736', 's207323960']
[13840.0, 13840.0]
[121.0, 119.0]
[215, 206]
p03137
u471212175
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M = map(int,input().split())\nl = list(map(int,input().split()))\nl = list(sorted(l))\n\nd = []\nfor i in range(M-1):\n d.append(abs(l[i+1]-l[i]))\nd = list(sorted(d))\nprint(d)\nwhile N != 1 and len(d) !=0:\n del d[len(d)-1]\n N -= 1\nsum = 0\nif len(d) >= 1:\n for i in range(len(d)):\n sum += d[i]\nprint(sum)\n', 'N,M = map(int,input().split())\nl = list(map(int,input().split()))\nl = list(sorted(l))\n\nd = []\nfor i in range(M-1):\n d.append(abs(l[i+1]-l[i]))\nd = list(sorted(d))\nwhile N != 1 and len(d) !=0:\n del d[len(d)-1]\n N -= 1\nsum = 0\nif len(d) >= 1:\n for i in range(len(d)):\n sum += d[i]\nprint(sum)\n']
['Wrong Answer', 'Accepted']
['s203408325', 's734299349']
[13960.0, 13960.0]
[160.0, 161.0]
[318, 309]
p03137
u475675023
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m=map(int,input().split())\nx=sorted([int(i) for i in input().split()])\nl=sorted([max(x[i]-x[i+1],-x[i]+x[i+1]) for i in range(m-1)])\nprint([sum(l[:-n+1]),0][n<m])', 'n,m=map(int,input().split())\nx=sorted([int(i) for i in input().split()])\nif n>=m:\n print(0)\nelse:\n l=sorted([x(i+1)-x(i) for i in range(m-1)])\n print(sum(l[:m-n]))', 'n,m=map(int,input().split())\nx=sorted([int(i) for i in input().split()])\nif n>=m:\n print(0)\nelse:\n l=sorted([x[i+1]-x[i] for i in range(m-1)])\n print(sum(l[:m-n]))']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s355289890', 's927071028', 's957083750']
[13840.0, 13832.0, 13840.0]
[141.0, 81.0, 106.0]
[164, 166, 166]
p03137
u480200603
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n, m = map(int, input().split())\nx = list(map(int, input().split()))\nx.sort()\ndiff = []\nif n < m:\n print(0)\n exit()\nfor i in range(1, m):\n diff.append(x[i] - x[i - 1])\ndiff.sort()\nprint(sum(diff[:m-n]))\n', 'n, m = map(int, input().split())\nx = list(map(int, input().split()))\nx.sort()\ndiff = []\nif M <= N:\n print(0)\n\nfor i in range(1, m):\n diff.append(x[i] - x[i - 1])\ndiff.sort()\nprint(sum(diff[:m-n]))\n', 'n, m = map(int, input().split())\nx = list(map(int, input().split()))\nx.sort()\ndiff = []\nif m <= n:\n print(0)\n exit()\nfor i in range(1, m):\n diff.append(x[i] - x[i - 1])\ndiff.sort()\nprint(sum(diff[:m-n]))\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s414059046', 's845077799', 's018435895']
[13968.0, 13968.0, 13960.0]
[110.0, 77.0, 110.0]
[212, 203, 213]
p03137
u485716382
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['def main():\n N, M = map(int, input().split())\n X = list(map(int, input().split()))\n \n X = sorted(X)\n print(X)\n X = sorted([X[i+1]-X[i] for i in range(M-1)], reverse=True)\n print(X)\n print(sum(X[N-1:]))\n\n\nmain()', 'def main():\n N, M = map(int, input().split())\n X = list(map(int, input().split()))\n \n X = sorted(X)\n X = sorted([X[i+1]-X[i] for i in range(M-1)], reverse=True)\n print(sum(X[N-1:]))\n\n\nmain()']
['Wrong Answer', 'Accepted']
['s378819484', 's412071483']
[13968.0, 13968.0]
[114.0, 101.0]
[218, 196]
p03137
u487594898
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['#!/usr/bin/env python3\n# sys.stdin.readline()\nimport numpy as np\n\nimport math\n\nn,m = map(int,input().split())\nA = list(map(int,input().split()))\nA.sort()\nB = [-A[i]+A[i+1] for i in range(m-1)]\nB.sort()\nprint(B,sum(B[0:max(m-n,0)]))', '#!/usr/bin/env python3\n# sys.stdin.readline()\nimport numpy as np\n\nimport math\n\nn,m = map(int,input().split())\nA = list(map(int,input().split()))\nA.sort()\nB = [-A[i]+A[i+1] for i in range(m-1)]\nB.sort()\nprint(sum(B[0:max(m-n,0)]))']
['Wrong Answer', 'Accepted']
['s455170239', 's246055414']
[22900.0, 23044.0]
[316.0, 234.0]
[231, 229]
p03137
u489762173
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
["import sys\n\ndef main():\n N, M = list(map(int, input().split()))\n X = list(map(int, input().split()))\n\n if N >= M:\n print('0')\n exit()\n\n X = sorted(X)\n\n kukan = []\n for i in range(1, M):\n kukan.append(X[i]-X[i-1])\n\n kukan = sorted(kukan, reverse=True)\n\n jogai = 0\n for j in range(N-1):\n jogai += kukan[j]\n\n print(X[M-1] - X[0] - jogai)\n\n print(kukan)\n\nmain()", "import sys\n\ndef main():\n N, M = list(map(int, input().split()))\n X = list(map(int, input().split()))\n\n if N >= M:\n print('0')\n exit()\n\n X = sorted(X)\n\n kukan = []\n for i in range(1, M):\n kukan.append(X[i]-X[i-1])\n\n kukan = sorted(kukan, reverse=True)\n\n jogai = 0\n for j in range(N-1):\n jogai += kukan[j]\n\n print(X[M-1] - X[0] - jogai)\n\nmain()"]
['Wrong Answer', 'Accepted']
['s217762986', 's325883700']
[13968.0, 13968.0]
[114.0, 108.0]
[418, 400]
p03137
u492835011
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['nm = [int(i) for i in input().split()]\npoints = sorted([int(i) for i in input().split()])\nn, m = nm[0], nm[1]\n\nif n >= m:\n print(0)\nelif n == 1:\n print(max(points) - min(points))\nelse:\n list_diff = [points[i+1] - points[i] for i in range(m-1)]\n list_th = []\n for i in range(n-1):\n max_index = list_diff.index(max(list_diff))\n list_th.append(max_index)\n list_diff[max_index] = 0\n \n x = points[0]\n th = 0\n count = 0\n print(list_th)\n while x < points[-1]:\n if x == points[list_th[th]]:\n x = points[list_th[th]+1]\n th += 1\n else:\n x += 1\n count += 1\n if x == points[-1]:\n break\n print(count)', 'n, m = list(map(int, input().split()))\nxxx = list(map(int, input().split()))\n \nif n >= m:\n print(0)\n exit()\nxxx.sort()\nddd = [b - a for a, b in zip(xxx, xxx[1:])]\nddd.sort()\nprint(sum(ddd[:m - n]))']
['Runtime Error', 'Accepted']
['s589584498', 's177935375']
[13960.0, 13968.0]
[2104.0, 95.0]
[732, 203]
p03137
u494058663
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['N,M = map(int,input().split())\ntmpX =list(input().split())\nX = [int(s) for s in tmpX]\nX.sort()\nX_difference=[]\nfor i in range(M-1):\n X_difference.append(X[i+1]-X[i])\nprint(X_difference)\nX_difference.sort(reverse = True)\ndel X_difference[0:N-1:]\nprint(sum(X_difference))', 'N,M = map(int,input().split())\ntmpX =list(input().split())\nX = [int(s) for s in tmpX]\nX.sort()\nX_difference=[]\nfor i in range(M-1):\n X_difference.append(X[i+1]-X[i])\n\nX_difference.sort(reverse = True)\ndel X_difference[0:N-1:]\nprint(sum(X_difference))']
['Wrong Answer', 'Accepted']
['s911179724', 's617592327']
[14984.0, 14864.0]
[121.0, 127.0]
[272, 253]
p03137
u496744988
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n, m = map(int, input().split())\nx = sorted(list(map(int, input().split())))\nprint(x)\ndiff = sorted([abs(x[i+1] - x[i]) for i in range(len(x)-1)])\nprint(diff)\nprint(abs(x[-1] - x[0]) - sum(diff[-1:-n:-1])) if n < m else print(0)\n', 'n, m = map(int, input().split())\nx = sorted(list(map(int, input().split())))\ndiff = sorted([abs(x[i+1] - x[i]) for i in range(len(x)-1)])\nprint(diff)\nprint(x[-1] - x[0] - sum(diff[-1:n:-1])) if n < m else print(0)\n', 'n, m = map(int, input().split())\nx = sorted(list(map(int, input().split())))\ndiff = sorted([abs(x[i+1] - x[i]) for i in range(len(x)-1)])\nprint(abs(x[-1] - x[0]) - sum(diff[-1:-n:-1])) if n < m else print(0)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s223910100', 's415023323', 's963052528']
[13960.0, 13960.0, 13960.0]
[124.0, 121.0, 107.0]
[229, 214, 208]
p03137
u496815777
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n, m = map(int, input().split())\nx = sorted(list(map(int, input().split())))\ny = sorted([x[i + 1] - x[i] for i in range(m - 1)])\ntotal = 0\n\nfor i in range(m - 3):\n total += y[i]\n\nprint(total)', 'n, m = map(int, input().split())\nx = sorted(list(map(int, input().split())))\nif m > 1:\n y = sorted([x[i + 1] - x[i] for i in range(m - 1)])\ntotal = 0\n\nif m == 1:\n print(0)\nelif m == 2 and n == 1:\n print(y[0])\nelif m == 2 and n > 1:\n print(0)\nelse:\n for i in range(m - 3):\n total += y[i]\n print(total)', 'n, m = map(int, input().split())\nx = sorted(list(map(int, input().split())))\nif m > 1:\n y = sorted([x[i + 1] - x[i] for i in range(m - 1)])\ntotal = 0\n\nif n >= m:\n print(0)\nelse:\n for i in range(m - n):\n total += y[i]\n print(total)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s315615299', 's453337951', 's607539095']
[13960.0, 13968.0, 13968.0]
[120.0, 119.0, 108.0]
[192, 309, 237]
p03137
u498620941
2,000
1,048,576
We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move: **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1. Note that the coordinates where we initially place the pieces are already regarded as visited. Find the minimum number of moves required to achieve the objective.
['n,m = map(int,input().split())\nx = [i for i in map(int,input().split())]\n\nx.sort()\ndiff = []\nfor i in range(m-1):\n diff.append(x[i+1] - x[i])\ndiff.sort(reverse= True)\nans = sum(diff) - sum(diff[0:n])\nprint(ans)', 'n,m = map(int,input().split())\nx = [i for i in map(int,input().split())]\n\nx.sort()\ndiff = []\nfor i in range(m-1):\n diff.append(x[i+1] - x[i])\ndiff.sort(reverse= True)\nans = sum(diff) - sum(diff[0:n-1])\nprint(ans)']
['Wrong Answer', 'Accepted']
['s816702179', 's330831824']
[13840.0, 13832.0]
[118.0, 126.0]
[213, 215]