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()
if N>=M:
    print(0)
else:
    L=[X[i+1]-X[i] for i in range(M-1)]
    L.sort(reverse=True)
    s=sum([L[i] for i in range(N-1)])
    print(L)
    print(max(X)-min(X)-s)


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


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

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):
n, m = map(int, input().split())
x = list(map(int, input().split()))
 
if n >= len(x):
    print(0)
    exit()

l = []
x.sort()
 
for i in range(m-1):
    diff = x[i+1] - x[i]
    ls.append(diff)

l.sort(reverse=True)
ans = sum(ls)
 
for i in range(n-1):
    ans -= ls[i]
print(ans)

n, m = map(int, input().split())
x = list(map(int, input().split()))
 
if n >= len(x):
    print(0)
    exit()
l = []
x.sort()
 
for i in range(m-1):
    diff = x[i+1] - x[i]
    ls.append(diff)
l.sort(reverse=True)
ans = sum(ls)
 
for i in range(n-1):
    ans -= ls[i]
print(ans)

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

if n >= len(x):
    print(0)
    exit()

ls = []
x.sort()

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

ls.sort(reverse=True)
ans = sum(ls)

for i in range(n-1):
    ans -= ls[i]

print(ans)

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):
def nyu():
    N, M = map(int, input().split())
    X = list(map(int,input().split()))
    X.sort()
    return N,M,X


def kansu(N,M,X):

    x_abs = [X[m+1] -X[m] for m in range(M-1)]    
#    print(x_abs)
    cnt_n = N
    
    while cnt_n-1 > 0:
        x_abs[x_abs.index(max(x_abs))]  = -1
        cnt_n -= 1

    koma_max = 0
    sum = 0
    for m in range(M-1):
        if x_abs[m] == -1:
            sum =0
            continue
        else:
            sum += x_abs[m]
        if koma_max < sum:
            koma_max =sum
    print(koma_max)



    
    

    


N,M,X = nyu()
#print(X)

if M == 1:
    print(0)
else:
    kansu(N,M,X)

#print(S)



def nyu():
    N, M = map(int, input().split())
    X = list(map(int,input().split()))
    X.sort()
    return N,M,X


def kansu(N,M,X):

    x_abs = [X[m+1] -X[m] for m in range(M-1)]    
#    print(x_abs)

    
    x_abs.sort()

    koma_max = 0
    for m in range(M-N):
        koma_max += x_abs[m]

    print(koma_max)


N,M,X = nyu()
#print(X)

if M == 1:
    print(0)
else:
    kansu(N,M,X)

#print(S)



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()))
s=list(map(int,input().split()))

a.sort()
term=[]
if n-m>=0:
    print(0)
else:
    for i in range(m-1):
        term.append(s[i+1]-s[i])
    
    term.sort()

    for i in range(n-1):
        del term[-1]
    
    print(sum(term))

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

s.sort()
term=[]
if n-m>=0:
    print(0)
else:
    for i in range(m-1):
        term.append(s[i+1]-s[i])
    
    term.sort()

    for i in range(n-1):
        del term[-1]
    
    print(sum(term))

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):
from sys import stdin

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

    if N >= M:
        print(0)
    return

    X.sort()
    n = [(i + 1, X[i+1] - X[i]) for i in range(M - 1)]
    n.sort(reverse=1, key=lambda x: x[1])
    ans, s1 = 0, 0
    for i in range(N - 1):
        s2 = n[i][0]
        ans += X[s1:s2][-1] - X[s1:s2][0]
        s1 = s2
    ans += X[s1:][-1] - X[s1:][0]
    print(ans)

input = lambda: stdin.readline()
main()


from sys import stdin

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

    if N >= M:
        print(0)
        return

    X.sort()
    n1 = [(i + 1, X[i+1] - X[i]) for i in range(M - 1)]
    n1.sort(reverse=1, key=lambda x: x[1])
    n2 = n1[:N-1]
    n2.sort()

    ans, i = 0, 0
    for j, _ in n2:
        ans += X[i:j][-1] - X[i:j][0]
        i = j
    ans += X[i:][-1] - X[i:][0]
    print(ans)

input = lambda: stdin.readline()
main()


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 main():
    n, m, *x = map(int, open(0).read().split())
    if m >= n:
        print(0)
        return
    x.sort()
    a = [x[i + 1] - x[i] for i in range(m - 1)]
    a.sort()
    ans = sum(a) - sum(a[-n+1:])
    print(ans)

if __name__ == '__main__':
    main()


def main():
    n, m, *x = map(int, open(0).read().split())
    if n >= m:
        print(0)
        return
    x.sort()
    a = [x[i + 1] - x[i] for i in range(m - 1)]
    a.sort()
    if n == 1:
        print(sum(a))
        return
    ans = sum(a) - sum(a[-n+1:])
    print(ans)

if __name__ == '__main__':
    main()


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)
else:
    x = sorted(x)
    x = [x[i+1]-x[i] for i in range(len(x)-1)]

    x = sorted(x, reverse=True)
    x = xx[n-1:]
    ans = 0
    for i in x:
        ans+=i
    print(ans)


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

if n >= m:
    print(0)
else:
    x = sorted(x)
    x = [x[i+1]-x[i] for i in range(len(x)-1)]

    x = sorted(x, reverse=True)
    x = x[n-1:]
    ans = 0
    for i in x:
        ans+=i
    print(ans)


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 -*-
from itertools import starmap

n, m = map(int, input().split())
l = sorted(list(map(int, input().split())))
divcount = n - 1

if n == 1:
    print(max(l) - min(l))
else:
    divl = sorted(list(starmap(lambda a,b: a - b, zip(l[1:], l[:m - 2])), reverse = True)
    for i in range(divcount):
        del divl[0]
    
    print (sum(divl))


# -*- coding: utf-8 -*-
 
n, m = map(int, input().split())
l = sorted(list(map(int, input().split())))
divcount = n - 1
 
l1 = l[1:]
l2 = l[:m - 1]
divl = []
 
for i in range(m - 1):
    divl.append(l1[i] - l2[i])
 
divl.sort(reverse = True)
 
if n == 1:
    print(max(l) - min(l))
else:
    if m > n:
        for i in range(divcount):
            del divl[0]
    
        print (sum(divl))
    
    else:
        print(0)

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()))
X=sorted(X)
distance=[]
for i in range(M-1):
    distance.append(X[i+1]-X[i])


distance=sorted(distance, reverse=True)
print(distance)
answer=sum(distance[(N-1):])
print(answer)

N, M = map(int, input().split())
X=list(map(int, input().split()))
X=sorted(X)
distance=[]
for i in range(M-1):
    distance.append(X[i+1]-X[i])


distance=sorted(distance, reverse=True)
#print(distance)
answer=sum(distance[(N-1):])
print(answer)

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 = input().split()
X = list(map(int, input().split()))

if N >= M:
    print(0)
else:
    X.sort()
    L = []
    for i in range(M-1):
        L.append(X[i+1]-X[i])
    L.sort(reverse=True)
    print(X[M]-X[0]-sum(L[:N-1]))


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

if N >= M:
  print(0)
else:
  X.sort()
  L = []
  for i in range(M-1):
    L.append(X[i+1]-X[i])
  L.sort(reverse=True)
  print(X[M-1]-X[0]-sum(L[:N-1]))


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

if N >= M:
    print(0)
else:
    X.sort()
    L = []
    for i in range(M-1):
        L.append(X[i+1]-X[i])
    L.sort(reverse=True)
    print(X[M-1]-X[0]-sum(L[:N-1]))


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

if N >= M:
    print(0)
else:
    X.sort()
    L = []
    for i in range(M-1):
        L.append(X[i+1]-X[i])
    L.sort(reverse=True)
    print(X[M-1]-X[0]-sum(L[:N-1]))


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 = list(map(int, input().split()))
x = list(map(int, input().split()))

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

ans = 0
for i in range(0, len(xs)):
  if m - i <= n:
    break
  ans += xs[i]
print(ans)

n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
xs = []
for i in range(0, len(x)-1):
  xs.append(x[i+1] - x[i])
xs.sort()

ans = 0
for i in range(0, len(xs)):
  if m - i <= n:
    break
  ans += xs[i]
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 = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
sa = [0 for i in range(M-1)]
# print(X)
for i in range(M-1):
    sa[i] = X[i+1]-X[i]
sa = sorted(sa)
print(sa)
if N >= M:
    print(0)
else:
    print(sum(sa[0:-N+1]))

N,M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
sa = [0 for i in range(M-1)]
# print(X)
for i in range(M-1):
    sa[i] = X[i+1]-X[i]
sa = sorted(sa)
# print(sa)
if N >= M:
    print(0)
elif N == 1:
    print(sum(sa))
else:
    print(sum(sa[0:-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 = [int(x) for x in input().split()]
N = NM[0]
M = NM[1]
X = [int(x) for x in input().split()]
X.sort()
print(X)
LL = 0
if N > M:
    #print(LL)
else:
    L = [0] * (M - 1)
    for i in range (0, M - 1):
        L[i] = X[i + 1] - X[i]
    L.sort()
    #print(L)
    for i in range(0, M - N):
        LL += L[i]
    print(LL)

NM = [int(x) for x in input().split()]
N = NM[0]
M = NM[1]
X = [int(x) for x in input().split()]
X.sort()
print(X)
LL = 0
if N > M:
    print(LL)
else:
    L = [0] * (M - 1)
    for i in range (0, M - 1):
        L[i] = X[i + 1] - X[i]
    L.sort()
    print(L)
    for i in range(0, M - N):
        LL += L[i]
    print(LL)

NM = [int(x) for x in input().split()]
N = NM[0]
M = NM[1]
X = [int(x) for x in input().split()]
X.sort()
#print(X)
LL = 0
if N > M:
    print(LL)
else:
    L = [0] * (M - 1)
    for i in range (0, M - 1):
        L[i] = X[i + 1] - X[i]
    L.sort()
    #print(L)
    for i in range(0, M - N):
        LL += L[i]
    print(LL)

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(map(int,input().split()))
if X[0] < 0:
    X[0] *= -1
for i in range(1,M):
    X[i] = X[0]+X[i]
X[0] = 0
mean = max(X)/N
ans = 0
for i in range(len(X)):
    if N == 0:
        break
    for j in range(i+1,len(X)):
        if N == 0:
            break
        if X[j]-X[i] >= mean:
            ans = X[j-1]-X[i]
            N -= 1
            break
        mean = (max(X)-X[i])//N
        for j in range(i+1,len(X)):
            if X[j]-X[i] >= mean and N != 0:
                ans = X[j-1]-X[i]
                N -= 1
                break
print(ans)

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

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

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 solve():
    n, m = map(int, input().split())
    x = list(map(int, input().split()))
    x.sort()
    diff = [x[i + 1] - x[i] for i in range(m)]
    diff.sort(reverse=True)
    return sum(diff[n - 1:])


if __name__ == "__main__":
    print(solve())


def solve():
    n, m = map(int, input().split())
    x = sorted(list(map(int, input().split())))
    diff = sorted([x[i + 1] - x[i] for i in range(m)], reverse=True)
    return sum(diff[n - 1:])


if __name__ == "__main__":
    print(solve())


def solve():
    n, m = map(int, input().split())
    if n >= m:
        return 0
    x = sorted(list(map(int, input().split())))
    diff = sorted([x[i + 1] - x[i] for i in range(m)], reverse=True)
    return sum(diff[n - 1:])


if __name__ == "__main__":
    print(solve())


def solve():
    n, m = map(int, input().split())
    x = sorted(list(map(int, input().split())))
    diff = sorted([x[i + 1] - x[i] for i in range(m - 1)], reverse=True)
    return sum(diff[n - 1:])


if __name__ == "__main__":
    print(solve())


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 = sorted(map(int,input().split()))
l = sorted([x[i+1]-x[i]for i in range(m-1)])
if n >=m:
    print(0)
else:
    print(sum(l)-sum([-i-1]for i in range(n-1)))

n, m = map(int, input().split())
x = sorted(set(map(int, input().split())))
t = []
for i, j in zip(x, x[1:]):
    t += [abs(i - j)]
t = sorted(t, reverse=True)
print(sum(t[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())
X=[int(i) for i in input().split()]
X.sort()

Y=list()
for i in range(M)[1:]
  Y.append(X[i]-X[i-1])

Y.sort()

if N==1:
  print(sum(Y))
else:
  print(sum(Y[:-(N-1)]))


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

if N==1:
  print(X[M-1]-X[0])
elif N>=M:
  print(0)
elif N+1=M:
  print(X[0])
else:
  Y=list()
  [Y.append(X[i]-X[i-1]) for i in range(M)[1:]]
  Y.sort()
  print(sum(Y[:-(N-1)]))


N=int(input())
M=int(input())

X=sorted([int(i) for i in input().split()])

Y=list()
before=X[0]
for i in X:
  diff = i - before
  if diff == 0:
    continue
  Y.append(diff)
  before = i

Y=sorted(Y)

print(sum(Y[:-(N-1)]))



N,M = map(int,input().split())
X=sorted(map(int, input().split()))
if N==1:
  print(X[M-1]-X[0])
elif N>=M:
  print(0)
else:
  print(sum(sorted([i-j for i,j in zip(X[1:],X)],reverse=True)[N-1:]))

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):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
li = na()
ls = []
if len(li) - 1 < n - 1:
    print(0)
else:
    list.sort(li)
    for i in range(len(li) - 1):
        ls.append(li[i + 1] - li[i])
    list.sort(ls)
    print(ls)
    print(ls[:-(n-1)])
    if n - 1 > 0:
        print(sum(ls[:-(n-1)]))
    else:
        print(0)

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
li = na()
ls = []
list.sort(li)
for i in range(len(li) - 1):
    ls.append(li[i + 1] - li[i])
ls = sorted(ls, reverse=True)
print(sum(ls[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 = list(map(int,input().split()))
if m =< n:
    print(0)
    quit()

x.sort()
dist_l = [0] * (m-1)

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

dist_l.sort()
print(sum(dist_l[:-(n-1)]))

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

x.sort()
dist_l = [0] * (m-1)

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

dist_l.sort()
print(sum(dist_l[:-(n-1)]) if n !=1 else sum(dist_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,C,K = map(int,input().split())
T = []
for _ in range(N):
    t = int(input())
    T.append(t)
T.sort()
angry = 0
ans = 0
c = 0
for i in T:
    if angry == 0:
        angry = i + K
    c += 1
    if i >= angry :
        #print(i,angry)
        angry = i + K
        ans += 1
        c = 1
    if c == C:
        angry = 0
        ans += 1
        c = 0
    #print(ans,angry,c)
if c > 0:
    ans += 1
if C == 1:
    ans = C
print(ans)  

N,M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
if M <= N :
    ans = 0
else:
    Y = []
    for i in range(M-1):
        Y.append(X[i+1] - X[i])
    Y.sort(reverse=True)
    ans = X[-1] - X[0]
    Y = Y[:N-1]
    for i in Y:
        ans -= i
print(ans)

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()))
x = sorted(x)
d = []
for i in range(len(x)-1):
    d.append(x[i+1]-x[i])
d = sorted(d)
if n==1:
    print(x[-1]-x[0])
elif n>=len(x):
    print(0)
else:
    ans = 0
    for i in range(n-1):
        ans+=d[-i-1]
    print(ans)

n,m = map(int,input().split())
x = list(map(int,input().split()))
x = sorted(x)
d = []
for i in range(len(x)-1):
    d.append(x[i+1]-x[i])
d = sorted(d)
if n==1:
    print(x[-1]-x[0])
elif n>=len(x):
    print(0)
else:
    print(d)
    dis = 0
    for i in range(n-1):
        dis+=d[-i-1]
    print(sum(d)-dis)

n,m = map(int,input().split())
x = list(map(int,input().split()))
x = sorted(x)
d = []
for i in range(len(x)-1):
    d.append(x[i+1]-x[i])
d = sorted(d)
if n==1:
    print(x[-1]-x[0])
elif n>=len(x):
    print(0)
else:
    dis = 0
    for i in range(n-1):
        dis+=d[-i-1]
    print(sum(d)-dis)

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):
import sys

N,M=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
a=[x[i+1]-x[i] for i in range(M-1)]

if N>=M:
    print(0)
    sys.exit()
    
print(sum(a[:M-N]))

import sys

N,M=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
a=[x[i+1]-x[i] for i in range(M-1)]
a.sort()

if N>=M:
    print(0)
    sys.exit()
    
print(sum(a[: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(set(map(int, input().split())))
l = [x[i+1]-x[i] for i in range(n-1)]
l.sort(reverse=True)
print(sum(l[n-1:]))

n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
l = [x[i+1]-x[i] for i in range(m-1)]
l.sort(reverse=True)
print(x[-1]-x[0]-sum(l[: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())
x = list(map(int, input().split()))
x.sort(
y = []
for i in range(m - 1):
    y.append(x[i + 1] - x[i])
y.sort()
count = 0
for i in range(m - n):
    count += y[i]
print(count)

n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
y = []
for i in range(m - 1):
    y.append(x[i + 1] - x[i])
y.sort()
count = 0
for i in range(m - n):
    count += y[i]
print(count)

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:
    print(0)
else:
    x=list(map(int,input().split()))
    x.sort()
    y=[]
    for i in range(m-1):
        y.append(x[i+1]-x[i])
    y.sort(reverse=True)
    ans=x[-1]-x[0]
    for i in range(m-1):
        ans-=y[i]
    print(ans)

n,m=map(int,input().split())
if n>=m:
    print(0)
#elif n
else:
    x=list(map(int,input().split()))
    x.sort()
    y=[]
    for i in range(m-1):
        y.append(x[i+1]-x[i])
    y.sort(reverse=True)
    ans=x[-1]-x[0]
    for i in range(n-1):
        ans-=y[i]
    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 = map(int, input().split())

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

if N >= M:
    print(0)
    exit()
diffs = [X[i+1] - X[i] for i in range(M-1)]
diffs.sort()
print(sum[diffs[:N-M]])

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

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

if N >= M:
    print(0)
    exit()
diffs = [X[i+1] - X[i] for i in range(M-1)]
diffs.sort()
print(sum(diffs[:M-N]))

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):
nandm = input().split()
numlist = input().split()
N = int(nandm[0])
M = int(nandm[1])
if N >= M:
    print(0)
else:
    intlist = [int(num) for num in numlist]
    intlist.sort()
    subtract = [intlist[i + 1] - intlist[i] for i in range(len(intlist) - 1)]
    subtract.sort()
    print(sum(subtract[M - N]))

nandm = input().split()
numlist = input().split()
N = int(nandm[0])
M = int(nandm[1])
if N >= M:
    print(0)
else:
    intlist = [int(num) for num in numlist]
    intlist.sort()
    subtract = [intlist[i + 1] - intlist[i] for i in range(len(intlist) - 1)]
    subtract.sort()
    print(sum(subtract[:(M - N)]))

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 numpy as np
import sys
N, M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()

X_list = list(np.diff(X))

if M-N < 1:
    print(0)
    sys.exit()

X_list.sort(reverse=True)
sum(X_list[N-1:])

import numpy as np
import sys
N, M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()

X_list = list(np.diff(X))

if M-N < 1:
    print(0)
    sys.exit()

X_list.sort(reverse=True)
print(sum(X_list[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):
import numpy as np
#from numba import njit


#A = np.array(list(map(int, input().split())))
(N,M) = map(int, input().split())
X = map(int, input().split())
X = sorted(X)

Y = []
for i in range(1,M):
    Y.append((i,X[i] - X[i-1]))

Y = sorted(Y, key=lambda x: (x[1]))
Y.reverse()

Z = []
last = 0
for i in range(0,min(N-1, len(Y))):
    print((last, Y[i][0]))
    if last < Y[i][0]:
        Z.append(X[last:Y[i][0]])
        last = Y[i][0]
Z.append(X[last:])
if len(Z) == 0:
    Z.append(X)

s = 0
for array in Z:
    if len(array) > 0:
        u = max(array)
        l = min(array)
        s += u - l

print(s)

import numpy as np
#from numba import njit


#A = np.array(list(map(int, input().split())))
(N,M) = map(int, input().split())
X = map(int, input().split())
X = sorted(X)

Y = []
for i in range(1,M):
    Y.append((i,X[i] - X[i-1]))

Y = sorted(Y, key=lambda x: (x[1]))
Y.reverse()

Z = []
last = 0
for i in range(0,min(N-1, len(Y))):
    Z.append(X[last:Y[i][0]])
    last = Y[i][0]
if len(Z) == 0:
    Z.append(X)

s = 0
for array in Z:
    u = max(array)
    l = min(array)
    s += u - l

print(s)

import numpy as np
#from numba import njit


#A = np.array(list(map(int, input().split())))
(N,M) = map(int, input().split())
X = map(int, input().split())
X = sorted(X)

Y = []
for i in range(1,M):
    Y.append((i,X[i] - X[i-1]))

Y = sorted(Y, key=lambda x: (x[1]))
Y.reverse()

I = list(map(lambda x: x[0], Y[0:min(N-1, len(Y))]))
I.sort()

Z = []
last = 0
for i in range(0,min(N-1, len(Y))):
    if last < I[i]:
        Z.append(X[last:I[i]])
        last = I[i]
Z.append(X[last:])
if len(Z) == 0:
    Z.append(X)

s = 0
for array in Z:
    if len(array) > 0:
        u = max(array)
        l = min(array)
        s += u - l

print(s)

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()))

x.sort()

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

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

x.sort()

if n>=m:
    print(0)
    exit()
sa=[]
for i in range(m-1):
    sa.append(x[i+1]-x[i])
sa.sort(reverse=True)
ans=x[-1]-x[0]
for i in range(n-1):
    ans-=sa[i]
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=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
a=[x[i+1]-x[i]for i in range(m-1)]
if m<=n:print(0);exit()
a.sort()
print(sum(a[:m-n+1]))

n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
a=[x[i+1]-x[i]for i in range(m-1)]
if m<=n:print(0);exit()
a.sort()
print(sum(a[: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()))
X = list(set(X))
X.sort()
M = len(X)
L = [X[i + 1] - X[i] for i in range(M - 1)]
L.sort()
if N >= M:
    print("0")
else:
    print(L)
    print(sum(L[:M - N]))

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

N, M = map(int, input().split())
X = list(map(int, input().split()))
X = list(set(X))
X.sort()
M = len(X)
L = [X[i + 1] - X[i] for i in range(len(X) - 1)]
L.sort()
if N >= M:
    print("0")
else:
    print(sum(L[: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):
# -*- coding: utf-8 -*-


from sys import stdin


############################################
#from sys import stdin
import numpy as np

# read data for n sequences.
input = stdin.readline().split()
m = int(input[0])
n = int(input[1])
#n = int(stdin.readline().split()[1])
data = np.zeros(n)
d = stdin.readline().split()
for i,x in enumerate(d):
    data[i] = int(x)
data = sorted(data)

dif = np.zeros(len(data)-1)
for x in range(0, len(data)-1):
    dif[x] = data[x+1]-data[x]

out = 0

# split in m data.
#print(data)
dif = np.zeros(len(data)-1)
for x in range(0, len(data)-1):
    dif[x] = data[x+1]-data[x]
maxdif = sorted(dif, reverse=True)[:m-1]
index=[]
for i, x in enumerate(dif):
    if x in maxdif: 
        index.append(i)


for i,x in enumerate(index):
    if not x == 0:
        if i==0:
            out += np.sum(data[:x])
        elif x==len(data):
            None
        else:
            out += np.abs(data[x]-data[index[i-1]+1])

print(out)
            
        

    

#print(data)

    


topdif = sorted(dif, reverse=True)[:m]
topkey=[]
for i,x in enumerate(dif):
    if x in topdif:
        topkey.append(i)


from sys import stdin



############################################
#from sys import stdin
import numpy as np

# read data for n sequences.
input = stdin.readline().split()
m = int(input[0])
n = int(input[1])
#n = int(stdin.readline().split()[1])
data = np.zeros(n)
d = stdin.readline().split()
for i,x in enumerate(d):
    data[i] = int(x)
data = sorted(data)

dif = np.zeros(len(data)-1)
for x in range(0, len(data)-1):
    dif[x] = data[x+1]-data[x]

out = 0

# split in m data.
#print(data)
dif = np.zeros(len(data)-1)
for x in range(0, len(data)-1):
    dif[x] = data[x+1]-data[x]
out = sum(sorted(dif, reverse=True)[m-1:])

            

print(int(out))
            

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())
zahyo = []
for i in map(int,input().split()):
    zahyo += [i]
sum=0


def merge(p,q):
    result=[]
    i,j=0,0
    
    while i<len(p) and j<len(q):
        
        
        if p[i] <= q[j]:
            result.append(p[i])
            i+=1
        else:
            result.append(q[j])
            j+=1

    
    
    
    if i<len(p):
        result.extend(p[i:])
    if j<len(q):
        result.extend(q[j:])
    
    return result


def mergesort(a):
    
    if len(a)==1:
        return a
    
    p=mergesort(a[:len(a)//2])
    
    q=mergesort(a[len(a)//2:])
    
    return merge(p,q)

mergesort(zahyo)
gap = []
for i in range(M-1):
    gap += [zahyo[i+1]-zahyo[i]] 
mergesort(gap)
if N >= M:
    print(0)
elif N == 1:
    print(zahyo[M-1] - zahyo[0])
else:
    for i in gap[N-1:]:
        sum += i
    print(sum)

N, M= map(int, input().split())
zahyo = []
for i in map(int,input().split()):
    zahyo += [i]
sum=0


def merge(p,q):
    result=[]
    i,j=0,0
    
    while i<len(p) and j<len(q):
        
        
        if p[i] <= q[j]:
            result.append(p[i])
            i+=1
        else:
            result.append(q[j])
            j+=1

    
    
    
    if i<len(p):
        result.extend(p[i:])
    if j<len(q):
        result.extend(q[j:])
    
    return result


def mergesort(a):
    
    if len(a)==1:
        return a
    
    p=mergesort(a[:len(a)//2])
    
    q=mergesort(a[len(a)//2:])
    
    return merge(p,q)

if M==1:
    print(0)
else:
    zahyo = mergesort(zahyo)
    gap = []
    for i in range(M-1):
        gap += [zahyo[i+1]-zahyo[i]] 
    gap = mergesort(gap)
    if N >= M:
        print(0)
    else:
        for i in gap[:M-N]:
            sum += i
        print(sum)

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())
w = list(map(int,input().split()))
w.sort()
li = []
for i in range(len(w)-1):
    a = w[i+1]-w[i]
    li.append(a)
li.sort(reverse = True)


b = sum(li[:(n-1)])
d = abs(max(w)) + abs(min(w))

print(d-b)

n,m = map(int,input().split())
li = list(map(int,input().split()))
li2 = []
li.sort()
for i in range(m-1):
    li2.append(abs(li[i]-li[i+1]))
li2.sort()

if n >= m:
    print(0)
else:
    print(sum(li2[0:m-n]))

Verdicts: Wrong Answer

Accepted