TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

if N >= M:
    print(0)
else:
    sub_X = []
    for i in range(0, M - 1):
        sub_X.append((i, abs(X[i+1] - X[i])))
    sub_X.sort(key=lambda x: x[1], reverse=True)

    division = set()
    if len(sub_X) != 0:
        for i in range(N-1):
            division.add(sub_X[i][0])
    ans = 0
    start = X[0]
    for i in range(M):
        if i in division:
            ans += X[i] - start
            start = X[i+1]
        if i == M-1:
            ans += X[i] - start

    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
入力（後でいじる）
def pin(type=int):
    return map(type,input().split())


#solution:

N,M=pin()
P=sorted(list(pin()))
#print("*",P)
PP=[abs(P[j+1]-P[j]) for j in range(M-1)]
#print(PP)
Q=sorted(PP)
#print(Q)
if N>=M:
    print(0)
else:
    for i in range(N-1):
        Q.pop()
    print(sum(Q))


def pin(type=int):
    return map(type,input().split())


#solution:

N,M=pin()
P=sorted(list(pin()))
print("*",P)
PP=[abs(P[j+1]-P[j]) for j in range(M-1)]
print(PP)
Q=sorted(PP)
print(Q)
if N>=M:
    print(0)
else:
    for i in range(N-1):
        Q.pop()
    print(sum(Q))
    


def pin(type=int):
    return map(type,input().split())


#solution:

N,M=pin()
P=sorted(list(pin()))
#print("*",P)
PP=[abs(P[j+1]-P[j]) for j in range(M-1)]
#print(PP)
Q=sorted(PP)
#print(Q)
if N>=M:
    print(0)
else:
    for i in range(N-1):
        Q.pop()
    print(sum(Q))
    

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

a1 = list(int(i) for i in input().split())  
x = list(int(i) for i in input().split())  
x = np.sort(x)
n = a[0]

delta = []
for i in range(0,len(x) - 1):
    delta.append(x[i + 1] - x[i])

if n == 1:
    print(np.sum(delta))
else:
    delta = np.sort(delta)
    print(np.sum(delta[0:delta.size - (n - 2)]))

import numpy as np

a1 = list(int(i) for i in input().split())  
x = list(int(i) for i in input().split())  
x = np.sort(x)
n = a[0]

delta = []
for i in range(0,len(x) - 1):
    delta.append(x[i + 1] - x[i])

if n == 1:
    print(np.sum(delta))
else:
    delta = np.sort(delta)
    f = delta.size - (n - 2)
    print(np.sum(delta[0:f:]))

import numpy as np

a1 = list(int(i) for i in input().split())  
x = list(int(i) for i in input().split())  
x = np.sort(x)
n = a1[0]

delta = []
if len(x) <= n:
    print(0)
else:
    for i in range(0,len(x) - 1):
        delta.append(x[i + 1] - x[i])

    if n == 1:
        print(np.sum(delta))
    else:
        delta = np.sort(delta)
        f = delta.size - (n - 2)
        print(np.sum(delta[0:-(n-1):]))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

Ms = M -1
dest = list()

for i in range(Ms):
  K = X[i+1] - X[i]
  dest = list.append(K)

dest.sort()
L = 0
NM = N - M
for j in range(NM):
  L = L + dest(j)

print(L)

N, M = map(int, input().split( ))
datas = list(map(int, input().split( )))
datas.sort()
Ms = M - 1

dest = list()
K = 0
i = 0
for i in range(Ms):
  K = datas[i+1] - datas[i]
  dest.append(K)

dest.sort()
L = 0
MN = M - N
for j in range(MN):
  L = L + dest[j]

print(L)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    flag = [0 for fl in range(M)]
    X.sort()
    for _ in range(1,M):
        flag[_] += X[_] - X[_-1]
   for lp in range(N-1):
        flag.pop(flag.index(max(flag)))
        print(sum(flag))


N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    flag = [0 for fl in range(M)]
    X.sort()
    for _ in range(1,M+1):
        flag[_] += X[_] - X[_-1]
    for lp in range(len(flag)):
      	ff = flag.index(max(flag))
        flag.pop(ff)
        print(sum(flag))


N,M = map(int,input().split())
X = list(map(int,input().split()))
if N >= M :
    print(0)
    exit()
X.sort()
flag = [b-a for a,b in zip(X,X[1:])]
flag.sort()
print(sum(flag[:M-N:]))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,m=map(int,input().split())
x=list(map(int,input().split()))
x=sorted(x)

if n>=m:
    print(0)
    exit()

l=[]
for i in range(m-1):
    l+=[x[i+1]-x[i]]

l=sorted(l)
print(sum(l)-sum(l[:-(n-1)]))


n,m=map(int,input().split())
x=list(map(int,input().split()))
x=sorted(x)

if n>=m:
    print(0)
    exit()

l=[]
for i in range(m-1):
    l+=[x[i+1]-x[i]]

l=sorted(l)
print(sum(l)-sum(l[-n+1:]) if n!=1 else sum(l))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split(" "))
X = list(map(int, input().split(" ")))
X.sort()
total = X[-1]-X[0]
dif = [X[i+1] - X[i] for i in range(len(X)-1)]
dif.sort()
print(dif)
Y = [0 for i in range(N-1)]
for i in range(N-1):
	Y[i] = dif.pop()
print(total-sum(Y))

N, M = map(int, input().split(" "))
X = list(map(int, input().split(" ")))
X.sort()
total = X[-1]-X[0]
dif = [X[i+1] - X[i] for i in range(len(X)-1)]
dif.sort()
Y = [0 for i in range(N-1)]
for i in range(N-1):
  try:
    Y[i] = dif.pop()
  except:
    Y[i]=0
print(total-sum(Y))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import math
import sys
INF = 1000000

N, M = map(int, input().split())
points = list(map(int, input().split()))

points.sort()
print(points)

minLength = [INF for _ in range(M)]
arrays = []

for n in range(N):
  tmp_array = []
  index = minLength.index(max(minLength)) 
  minLength[index] = 0
  tmp_array.append(points[index])
  for r in arrays:
    if points[index] in r:
      r.remove(points[index])
  for i in range(M):
    if minLength[i] > abs(points[i] - points[index]):
      for r in arrays:
        if points[i] in r:
          r.remove(points[i])
      tmp_array.append(points[i])
      minLength[i] = abs(points[i] - points[index])
  arrays.append(tmp_array)
  if all([True if i == 0 else False for i in minLength]):
    print(0)
    sys.exit()


ans = 0
for a in arrays:
  mi = min(a)
  ma = max(a)
  ans += abs(ma - mi)
print(ans)

import sys
INF = 1000000

N, M = map(int, input().split())
points = list(map(int, input().split()))

points.sort()
print(points)

minLength = [INF for _ in range(M)]
arrays = []

for n in range(N):
  tmp_array = []
  index = minLength.index(max(minLength)) 
  minLength[index] = 0
  tmp_array.append(points[index])
  for r in arrays:
    if points[index] in r:
      r.remove(points[index])
  for i in range(M):
    if minLength[i] > abs(points[i] - points[index]):
      for r in arrays:
        if points[i] in r:
          r.remove(points[i])
      tmp_array.append(points[i])
      minLength[i] = abs(points[i] - points[index])
  arrays.append(tmp_array)
  if all([True if i == 0 else False for i in minLength]):
    print(0)
    sys.exit()


ans = 0
for a in arrays:
  mi = min(a)
  ma = max(a)
  ans += abs(ma - mi)
print(ans)

n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()

ans = [abs(x[i+1] - x[i]) for i in range(m-1)]
ans.sort()

print(sum([ans[i] for i in range(m-n)]))
    


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def iread():
    return int(input())


def sread():
    return input()


def aread_int():
    tmp = input().split()
    ret = [int(i) for i in tmp]
    return ret


def aread_str():
    return input().split()

if __name__ == '__main__':
    n, m = map(int, input().split())
    
    x = aread_int()
    x = sorted(x)
    x_dist = [0] * (m - 1)
    for i in range(m - 1) :
        x_dist[i] += abs(x[i] - x[i + 1])
    
    if n > m :
        print(0)
        exit()
    
    x_dist = sorted(x_dist)
    print(x_dist)
    idx = len(x_dist) - 1
    cost = sum(x_dist)
    for i in range(n - 1) :
        cost -= x_dist[idx]
        x_dist[idx] = 0
        idx -= 1

    print(cost)

def iread():
    return int(input())


def sread():
    return input()


def aread_int():
    tmp = input().split()
    ret = [int(i) for i in tmp]
    return ret


def aread_str():
    return input().split()

if __name__ == '__main__':
    n, m = map(int, input().split())
    
    x = aread_int()
    x = sorted(x)
    x_dist = [0] * (m - 1)
    for i in range(m - 1) :
        x_dist[i] += abs(x[i] - x[i + 1])
    
    if n > m :
        print(0)
        exit()
    
    x_dist = sorted(x_dist)
    idx = len(x_dist) - 1
    cost = sum(x_dist)
    for i in range(n - 1) :
        cost -= x_dist[idx]
        x_dist[idx] = 0
        idx -= 1

    print(cost)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N,M = map(int,input().split())
L = list(map(int,input().split()))
if N >= M :
    ans = 0
else :
    L = sorted(L)
    A = []
    for i in range(M-1) :
        A.append(L[i+1]-L[i])
    A = sorted(A)
    ans = A[:M-N]
print(ans)


N,M = map(int,input().split())
L = list(map(int,input().split()))
if N >= M :
    ans = 0
else :
    L = sorted(L)
    A = []
    for i in range(M-1) :
        A.append(L[i+1]-L[i])
A = sorted(A)
ans = A[:M-N]
print(ans)


N,M = map(int,input().split())
L = list(map(int,input().split()))
L = sorted(L)
A = []
for i in range(M-1) :
    A.append(L[i+1] - L[i])
A = sorted(A)
if N >= M :
    ans = 0
else :
    ans = sum(A[:M-N])
print(ans)


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int,input().split())
X = list(map(int,input().split()))

ans = sorted([X[x+1] - X[x] for x in range(M-1)])

if N >= M:
    print(0)
else:
    print(sum(ans[:M-N]))

N, M = map(int,input().split())
X = sorted(list(map(int,input().split())))

ans = sorted([X[x+1] - X[x] for x in range(M-1)])

if N >= M:
    print(0)
else:
    print(sum(ans[:M-N]))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,m = list(map(int,input().split()))

data = [int(s) for s in input().split()]
data.sort()
l = []
for i in range(m-1):
    l.append(data[i+1]-data[i])
l.sort(reverse = True)

x = 0
for i in range(m-1):
    x += l[i]
print(data[m-1] - data[0] - x)


n,m = list(map(int,input().split()))

data = [int(s) for s in input().split()]
data.sort()
l = []
if n >= m:
    print(0)
else:
    for i in range(m-1):
        l.append(data[i+1]-data[i])
    l.sort(reverse = True)

    x = 0
    for i in range(n-1):
        x += l[i]
    print(data[m-1] - data[0] - x)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,m=map(int,input().split())
x=[int(i) for i in input().split()]
if m==1 or n>m
    print(0)
else:
    x=sorted(x)

    if n==1:
        print(x[-1]-x[0])
    else:

        xsa=[]
        for i in range(len(x)-1):
            xsa.append(x[i+1]-x[i])

        xsa=sorted(xsa)

        print(sum(xsa[0:(m-n)]))


n,m=map(int,input().split())
x=[int(i) for i in input().split()]
if m==1:
    print(0)
else:
    x=sorted(x)

    if n==1:
        print(x[-1]-x[0])
    else:

        xsa=[]
        for i in range(len(x)-1):
            xsa.append(x[i+1]-x[i])

        xsa=sorted(xsa)

        print(xsa)

        print(sum(xsa[0:(m-n)]))

n,m=map(int,input().split())
x=[int(i) for i in input().split()]
if m==1 or n>m:
    print(0)
else:
    x=sorted(x)

    if n==1:
        print(x[-1]-x[0])
    else:

        xsa=[]
        for i in range(len(x)-1):
            xsa.append(x[i+1]-x[i])

        xsa=sorted(xsa)



        print(sum(xsa[0:(m-n)]))


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int,input().split())
X = sorted(list(map(int,input().split())))

tmp = sorted([X[i+1] - X[i] for i in range(M-1)])
if(M <= N):
  print(sum(tmp[:M-N]))
else:
  print(0)

N, M = map(int,input().split())
X = sorted(list(map(int,input().split())))

tmp = [abs(X[i+1] - X[i]) for i in range(M-1)]
if(tmp != []):
  tmp.remove([max(tmp) for _ in range(N-1)]
  print(sum(tmp))
else:
  print(0)

N, M = map(int,input().split())
X = sorted(map(int,input().split()))

X = sorted([X[i+1]-X[i] for i in range(M-1)])
ans = sum(X[:M-N])
if M <= N:
  ans = 0
print(ans)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
MOD = 10**9+7

n,m = MAP()
x = MAP()
x.sort()

if n>=m:
    print(0)
    exit(0)

tmp = x[m-1] - x[0]
if n==1:
    print(tmp)
    exit(0)

ll = []
ans = 0
for i in range(m-1):
    ll.append(x[i+1]-x[i])
ll.sort()
print(tmp-sum(ll[-(n-1):]))
print(ll)
print(ll[-(n-1):])

def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
MOD = 10**9+7

n,m = MAP()
x = MAP()
x.sort()

if n>=m:
    print(0)
    exit(0)

ll = []
for i in range(m-1):
    ll.append(x[i+1]-x[i])
ll.sort()
print(sum(ll[0:max(0, m - n)]))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())
X = list(map(int, input().split()))

if N >= M:
    print(0)
    exit()

X = sorted(X)
print(X)
d = [X[i + 1] - X[i] for i in range(len(X) - 1)]
d = sorted(d)
print('d', d)
if N == 1:
    print(sum(d))
else:
    print(sum(d[:-N + 1]))


N, M = map(int, input().split())
X = list(map(int, input().split()))

if N >= M:
    print(0)
    exit()

X = sorted(X)
# print(X)
d = [X[i + 1] - X[i] for i in range(len(X) - 1)]
d = sorted(d)
# print('d', d)
if N == 1:
    print(sum(d))
else:
    print(sum(d[:-N + 1]))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
x = list(map(int, input().split()))
x.sort()
d = []
for i in range(m - 1):
    x_d = x[i + 1] - x[i]
    d.append(x_d)
print(d)
d.sort()
if n > m:
    n = m
ans = sum(d[:m - n])
print(ans)


nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
x = list(map(int, input().split()))
x.sort()
d = []
for i in range(m - 1):
    x_d = x[i + 1] - x[i]
    d.append(x_d)
d.sort()
if n > m:
    n = m
ans = sum(d[:m - n])
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M= (int(i) for i in input().split())
if (N<M):
    X = list(int(i) for i in input().split())
    X.sort()
    Y = [X[i] - X[i-1] for i in range(1, len(X))].sort()
    print(sum(Y[0:M-N]))
else:
    print(0)


# -100 | -10 -3 0 2 9 | 17
# 0 | 90 97 100 102 109 | 117
#   90  7  3   2   7    6
# 90 7 7 6 3 2






N, M= (int(i) for i in input().split())
if (N<M)
    X = list(int(i) for i in input().split())
    X.sort()
    Y = [X[i] - X[i-1] for i in range(1, len(X))].sort()
    print(sum(Y[0:M-N]))
else:
    print(0)


# -100 | -10 -3 0 2 9 | 17
# 0 | 90 97 100 102 109 | 117
#   90  7  3   2   7    6
# 90 7 7 6 3 2






N, M= (int(i) for i in input().split())
if (N<M):
    X = list(int(i) for i in input().split())
    X.sort()
    Y = [X[i] - X[i-1] for i in range(1, len(X))]
    Y.sort()
    print(sum(Y[0:M-N]))
else:
    print(0)






Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N,M=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
ls.sort()
d=[ls[i+1]-ls[i] for i in range(M-1)]
d.sort()
for _ in range(N):
  if len(d)==0:
    break
  del d[0]
print(sum(d))

N,M=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
ls.sort()
d=[ls[i+1]-ls[i] for i in range(M-1)]
d.sort()
for _ in range(N-1):
  if len(d)==0:
    break
  del d[0]
print(sum(d))


N,M=[int(s) for s in input().split()]
if N>=M:
  print(0)
else:
  ls=[int(s) for s in input().split()]
  ls.sort()
  d=[ls[i+1]-ls[i] for i in range(M-1)]
  d.sort()
  print(sum(d[:M-N]))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#python3.4
def inpul(): return list(map(int, input().split()))

N, M = inpul()
X = inpul()

if(N >= M):
    print(0)

new_list = sorted(X)
diff_list = [new_list[i+1] - new_list[i] for i in range(M-1)]
new_dif_list = sorted(diff_list, reverse = True)
else:
  if(N  >= 2):
      for i in range(N-1):
          new_dif_list.pop(0)

  print(sum(new_dif_list))


#python3.4
def inpul(): return list(map(int, input().split()))

N, M = inpul()
X = inpul()

if(N >= M):
    print(0)
else:
  new_list = sorted(X)
  diff_list = [new_list[i+1] - new_list[i] for i in range(M-1)]
  new_dif_list = sorted(diff_list, reverse = True)

  if(N  >= 2):
    for i in range(N-1):
        new_dif_list.pop(0)

  print(sum(new_dif_list))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-


import copy

n, m = map(int, input().split())
ary = [int(s) for s in input().split()]

if n < m :
    ary.sort()
    sa = []
    
    for i in range(0, m - 1):
        sa.append(ary[i + 1] - ary[i])
    
    print(sa)
    
    sa.sort()
    
    for i in range(0, n - 1):
        sa.pop(-1)
    
    print(sum(sa))
else :
    print(0)

# -*- coding: utf-8 -*-


import copy

n, m = map(int, input().split())
ary = [int(s) for s in input().split()]

if n < m :
    ary.sort()
    sa = []
    
    for i in range(0, m - 1):
        sa.append(ary[i + 1] - ary[i])
    
    #print(sa)
    
    sa.sort()
    
    for i in range(0, n - 1):
        sa.pop(-1)
    
    print(sum(sa))
else :
    print(0)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N,M = list(map(int, input().split(" ")))
Xs = sorted(list(map(int, input().split(" "))))

if N >= M :
	print(0)
	exit()
	
darr = [Xs[i+1] - Xs[i]for i in range(M-1)]

print(darr)

# ??
for i in range(N-1):
	darr.pop(darr.index(max(darr)))
	
print(sum(darr))

import heapq
N,M = list(map(int, input().split(" ")))
Xs = sorted(list(map(int, input().split(" "))))

if N >= M :
	print(0)
	exit()
	
darr = [Xs[i+1] - Xs[i]for i in range(M-1)]

# print(darr)
heapq.heapify(darr)
res = 0

for _ in range(M - N):
	res += heapq.heappop(darr)
	
print(res)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,m=map(int,input().split())
x=list(map(int,input().split()))
l=[]
for i in range(n-1):
  l.append(x[i+1]-x[i])
l.sort(reverse=True)
cnt=sum(l[:m-1])
print(x[m-1]-x[0]-cnt)

n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
l=[]
for i in range(m-1):
  l.append(x[i+1]-x[i])
l.sort(reverse=True)
cnt=sum(l[:n-1])
print(sum(l)-cnt)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,m = map(int, input().split())
a = sorted(list(map(int ,input().split())), reverse=True)
d = []
for i in range(m-1):
  d += [a[i+1] - a[i]]
d.sort(reverse=True)
print(sum(d[n-1:]))

n,m = map(int, input().split())
a = sorted(list(map(int ,input().split())))
d = []
for i in range(m-1):
  d += [a[i+1] - a[i]]
d.sort(reverse=True)
print(sum(d[n-1:]))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import deque
N, M = map(int, input().split())
X = deque(map(int, input().split()))
if N >= M:
	print(0)
else:
	X.sort()
	x = 0
	y = deque([0] * (N - 1))
	for i in range(M - 1):
		a = X[i+1] - X[i]
		b = min(y)
		if a > b:
			y.remove(b)
			y.append(a)
			x += b
		else:
			x += a
	print(x)

N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M:
	print(0)
else:
	X.sort()
	Y = [0] * (M - 1)
	for i in range(M - 1):
		Y[i] = X[i+1] - X[i]
	Y.sort(reverse = True)
	print(max(X) - min(X) - sum(Y[:N - 1]))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n, m = map(int, input().split())
if n >= m:
  ans = 0
else:
  x = list(map(int, input().split()))
  x.sort()
  print(x)
  d = [x[i] - x[i-1] for i in range(1,m)]
  d.sort()
  print(d)
  ans = sum(d[:m-n])
print(ans)

n, m = map(int, input().split())
if n >= m:
  ans = 0
else:
  x = list(map(int, input().split()))
  x.sort()
  d = [x[i] - x[i-1] for i in range(1,m)]
  d.sort()
  ans = sum(d[:m-n])
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,m = list(map(int, input().split()))
x = list(map(int, input().split()))

if n >= m:
    print(0)
    exit()
else:
    difference = []
    x.sort()
 
    for i in range(m-1):
        difference.append(x[i+1]-x[i])
 
    difference.sort()
 
    print(sum(difference[:n-1]))


n,m = input().split()
n = int(n)
m = int(m)

row_x = input().split()

if n >= m:
    print(0)
else:
    difference = []
    x = sorted(row_x)

    for i in range(m-1):
        difference.append(x[i+1]-x[i])

    for i in range(n-1):
        difference.remove(max(difference))

    print(sum(difference))

n,m = list(map(int, input().split()))
x = list(map(int, input().split()))

if n >= m:
    print(0)
    exit()
else:
    difference = []
    x.sort()
 
    for i in range(m-1):
        difference.append(x[i+1]-x[i])
 
    difference.sort()
 
    print(sum(difference[:m-n]))


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M :
  print(0)
else:
  length = [0] * (M-1)
  for i in range(M-1):
    length[i](X[i+1]-X[i])
  length.sort()
  print(sum(length[:(M-N)]))

N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M :
  print(0)
else:
  length = [0] * (M-1)
  for i in range(M-1):
    length[i](X[i+1]-X[i])
  length.sort()
  print(sum(length[:M-N]))

N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
if N >= M :
  print(0)
else:
  length = [0] * (M-1)
  for i in range(M-1):
    length[i](X[i+1]-X[i])
  length.sort()
  print(sum(length[:(M-N)]))

N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
if N >= M :
  print(0)
else:
  length = [0] * (M-1)
  for i in range(M-1):
    length[i] = (X[i+1]-X[i])
  length.sort()
  print(sum(length[:(M-N)]))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N,M=map(int,input().split())
X=list(map(int,input().split()))
if(len(X)<=N):
  print(0)
else:
  #print(N,M,X)
  sort_X=sorted(X)
  #print(sort_X)
  #print(sort_X[1:],sort_X[0:len(sort_X)-1])
  X_sa=[x - y for (x, y) in zip(sort_X[1:], sort_X[0:len(X)-1])]
  #print(X_sa)
  sort_X_sa=sorted(X_sa)
  print(sort_X_sa)
  print(sort_X_sa[:M-N])
  print(sum(sort_X_sa[:M-N]))

N,M=map(int,input().split())
X=list(map(int,input().split()))
if(len(X)<=N):
  print(0)
else:
  #print(N,M,X)
  sort_X=sorted(X)
  #print(sort_X)
  #print(sort_X[1:],sort_X[0:len(sort_X)-1])
  X_sa=[x - y for (x, y) in zip(sort_X[1:], sort_X[0:len(X)-1])]
  #print(X_sa)
  sort_X_sa=sorted(X_sa)
  #print(sort_X_sa)
  #print(sort_X_sa[:M-N])
  print(sum(sort_X_sa[:M-N]))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,m=list(map(int,input().split(" ")))
list_x=list(map(int,input().split(" ")))

list_x.sort()
list_d=[]

if m<=n:
    print(0)
else:
    i=0
    while i<=m-2:
        list_d.append(list_x[i+1]-list_x[i])
        i+=1
    list_d.sort()
    print(sum(list_d[0:n-1:1]))
    

n,m=list(map(int,input().split(" ")))
list_x=list(map(int,input().split(" ")))

list_x.sort()
list_d=[]

if m<=n:
    print(0)
else:
    i=0
    while i<=m-2:
        list_d.append(list_x[i+1]-list_x[i])
        i+=1
    list_d.sort()
    print(sum(list_d[0:m-n:1]))
    print(list_d)

n,m=list(map(int,input().split(" ")))
list_x=list(map(int,input().split(" ")))

list_x.sort()
list_d=[]

if m<=n:
    print(0)
else:
    i=0
    while i<=m-2:
        list_d.append(list_x[i+1]-list_x[i])
        i+=1
    list_d.sort()
    print(sum(list_d[0:m-n:1]))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
B = [0]

N,M = map(int, input().split())
X = list(map(int, input().split()))
X = sorted(X)
print(X)
for i in range(1,M):
    x = X[i]-X[i-1]
    B.append(x)
B = sorted(B)
B = B[::-1]
print(B)
print(X[-1]-X[0]-sum(B[:N-1]))

B = [0]

N,M = map(int, input().split())
X = list(map(int, input().split()))
X = sorted(X)
for i in range(1,M):
    x = X[i]-X[i-1]
    B.append(x)
B = sorted(B)
B = B[::-1]
print(X[-1]-X[0]-sum(B[:N-1]))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split(" "))
X = [int(n) for n in input().split(" ")]

X = sorted(X)

if len(X) <= N:
	print(0)

else:
	l = []
	for n in range(len(X)):
		if n != 0:
			l.append(abs(X[n - 1] - X[n]))

	ans = 0
	l = sorted(l, reverse=False)
	print(l)
	for i in range(M - N):
		ans += l[0]
		l.pop(0)

	print(ans)

N, M = map(int, input().split(" "))
X = [int(n) for n in input().split(" ")]

X = sorted(X)

if len(X) <= N:
	print(0)

else:
	l = []
	for n in range(len(X)):
		if n != 0:
			l.append(abs(X[n - 1] - X[n]))

	ans = 0
	l = sorted(l, reverse=False)
	for i in range(M - N):
		ans += l.pop(0)

	print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n, m, *x = map(int, open(0).read().split())
x.sort()

n, m, *x = map(int, open(0).read().split())
x.sort()
d = [i-j for i, j in zip(x[1:], x)]
d.sort()
print(sum(d[:m-n]) if n < m else 0)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n, m = [int(x) for x in input().split()]
x = [int(x) for x in input().split()]

x.sort()
print(x)

dist = [0] * (m-1)
for i in range(m-1):
    dist[i] = x[i+1] - x[i]
dist.sort(reverse=True)

length = x[m-1]-x[0]
for i in range(n-1):
    length -= dist[i]

print(length)


n, m = [int(x) for x in input().split()]
x = [int(x) for x in input().split()]

x.sort()

dist = [0] * (m-1)
for i in range(m-1):
    dist[i] = x[i+1] - x[i]
dist.sort(reverse=True)

if m <= n:
    print(0)
else:
    length = x[m-1]-x[0]
    for i in range(n-1):
        length -= dist[i]
    print(length)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N,M = map(int,input().split())
list = list(map(int,input().split()))

list.sort()

dif = [b-a for a,b in zip(list,list[1:])]
dif.sort()
print(sum(dif[:M-N]) if N - M > 0 else 0)

N,M = map(int,input().split())
list = list(map(int,input().split()))
list.sort()

diff = [b-a for a,b in zip(list,list[1::])]
diff.sort(reverse=True)
print(sum(diff[N-1:]) if M-N >0 else 0)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N,M=map(int,input().split())
X=list(map(int,input().split()))
s=[]
sum=0
if M!=1:
    X.sort()
    for i in range(M-1):
        s.append(X[i+1]-X[i])
    t=[]
    for i in range(M-1):
        t.append(s[i])
    s.sort(reverse=True)
    buf=[[],[]]
    for i in range(N-1):
        buf[0].append(s[i])
        buf[1].append(t.index(s[i]))
    print(buf)
    buf[1].sort()
    for i in range(len(buf[1])):
        if i==0:
            sum+=X[buf[1][i]]-X[0]
        else:
            sum+=X[buf[1][i]]-X[buf[1][i-1]+1]
    sum+=X[M-1]-X[buf[1][-1]+1]
else:
    sum=0
    print(sum)



N,M=map(int,input().split())
X=list(map(int,input().split()))
X.sort()
a=[0 for i in range(M-1)]
for i in range(M-1):
    a[i]=X[i+1]-X[i]
a.sort(reverse=True)
a=a[N-1:]
print(sum(a))



Verdicts: Runtime Error

Accepted