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):
# 2019-11-12 13:20:54(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, m, *x = (int(i) for i in sys.stdin.read().split())
    x.sort()
    if n >= m:
        print(0)
        sys.exit()

    ran = x[-1] - x[0] + 1
    quotient, remainder = ran // n, ran % n
    total_count = 0
    for i in range(x[0], x[-1-remainder], quotient):
        print(i)
        current = [j for j in x if i <= j < i + quotient]
        if not current:
            total_count -= 1
            continue
        count = max(current) - min(current)
        total_count += count
    
    total_count += remainder
    print(total_count)



if __name__ == "__main__":
    main()


import sys
import numpy as np 

n, m = map(int, sys.stdin.readline().split())
x = np.array(sys.stdin.readline().split(), dtype=np.int64)
x.sort()

def main():
    d = np.sort(x[1:] - x[:-1])[::-1]
    d = np.concatenate((np.array([0]), np.cumsum(d)))
    res = d[m-1] - d[min(n, m) - 1]
    print(res)

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 = sorted([int(i) for i in input().split()])

D = sorted([X[i]-X[i+1] for i in range(M-1)])
print(sum(D[:M-N]))
    


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


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


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=input().split()
N = int(n)
M = int(m)
X = input().split()

X = [int(x) for x in X]

X.sort()
if M == 1:
    print(0)
    sys.exit()
elif M < 1:
    sys.exit()

minus = [X[i]-X[i-1] for i in range(1,M)]
#print(minus)

minus.sort()
#print(minus)
sum_num = 0
if N < M:
    for i in range(N+1):
        sum_num += minus[i]
    print(sum_num)
elif N >= M:
    print(0):

import sys

n,m=input().split()
N = int(n)
M = int(m)
X = input().split()

X = [int(x) for x in X]

X.sort()
if M == 1:
    print(0)
    sys.exit()
elif M < 1:
    sys.exit()

minus = [X[i]-X[i-1] for i in range(1,M)]
#print(minus)

minus.sort()
#print(minus)
sum_num = 0
if N < M:
    for i in range(N+1):
        sum_num += minus[i]
    print(sum_num)
elif N >= M:
    print(0):    

import sys

n,m=input().split()
N = int(n)
M = int(m)
X = input().split()

X = [int(x) for x in X]

X.sort()
if M == 1:
    print(0)
    sys.exit()
elif M < 1:
    sys.exit()

minus = [X[i]-X[i-1] for i in range(1,M)]
#print(minus)

minus.sort()
#print(minus)
sum_num = 0
if N < M:
    for i in range(M-N):
        sum_num += minus[i]
    print(sum_num)
elif N >= M:
    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):
a=input()
b=input()
c=a.split()
n=int(c[0])
d=b.split()
d=[int(i) for i in d]
d.sort(reverse=True)
count=0
ll=list()
for i in d:
    if count!=0:
        ll.append(c-i)
    c=i
    count+=1
ll.sort()
for i in range(n-1):
    ccc=len(ll)
    if ccc>=1
        del ll[-1]
print(sum(ll))


a=input()
b=input()
c=a.split()
n=int(c[0])
d=b.split()
d=[int(i) for i in d]
d.sort(reverse=True)
count=0
ll=list()
for i in d:
    if count!=0:
        ll.append(c-i)
    c=i
    count+=1
ll.sort()
for i in range(n-1):
    ccc=len(ll)
    if ccc>=1:
        del ll[-1]
print(sum(ll))


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):
if M <= N:
    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[-1]-X[0]-sum(L[:N-1]))

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

if M <= N:
    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[-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):
import sys

N, M = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]

if not nums:
    print(0)
    sys.exit()

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

mem = {}
nums.sort()

print(0)


import sys

N, M = [int(x) for x in input().split()]
nums = list(set([int(x) for x in input().split()]))

if not nums:
    print(0)
    sys.exit()

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

nums.sort()

rank = [(abs(nums[i] - nums[i-1]), (i-1, i)) for i in range(1, len(nums))]
rank = sorted(rank, reverse=True)[:N-1]

pos = [0] + [pos[1] for dis, pos in rank]
pos.sort()
ans = 0
for i in range(len(pos)):
    if i == len(pos)-1:
        ans += abs(nums[pos[i]] - nums[-1])
    else:
        ans += abs(nums[pos[i]] - nums[pos[i+1]-1])

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()
p = []
for i in range(1,m):
    p.append(X[i]-X[i-1])
p.sort()
print(sum(p[:m-n-1]))

N,M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
distance = []
for i in range(1,M):
    distance.append(X[i]-X[i-1])
distance.sort(reverse = 1)
print(sum(distance[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):
# input
N, M = map(int, input().split()) 
X = list(map(int, input().split()))

X.sort()
K = [
    abs(X[i] - X[i - 1])
    for i in range(1, N)
]

print(sum(K[:M - (N - 1)])

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

X.sort()
K = [
    abs(X[i] - X[i - 1])
    for i in range(1, N)
]

print(sum(K[:M - (N - 1)]))

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

X.sort()
K = [
    abs(X[i] - X[i - 1])
    for i in range(1, N)
]

print(sum(K[:M - (N - 1)]))

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

X.sort()
K = sorted(
    [
        abs(X[i] - X[i - 1])
        for i in range(1, M)
    ]
)

print(K)

print(sum(K[:M - (N - 1)]))

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

X.sort()
K = sorted(
    [
        abs(X[i] - X[i - 1])
        for i in range(1, M)
    ],
    reverse=True
)

print(K)

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


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

X.sort()
K = [
    abs(X[n] - X[n - 1])
    for i in range(1, N)
]

print(sum(K[:M - (N - 1)]))


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

X.sort()
K = sorted(
    [
        abs(X[i] - X[i - 1])
        for i in range(1, M)
    ],
    reverse=True
)

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

Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

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

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

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

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

Verdicts: Runtime Error

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

X.sort()
cnt = 0
arr = [0]*(M-1)
if N > M:
    ans = 0
else:
    for i in range(1,M):
        arr[i] = (abs(X[i-1]-X[i]))
    #print(arr)
    arr.sort()
    ans = sum(arr[0:M-N])
print(ans)



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

X.sort()
cnt = 0
arr = [0]*(M-1)
if N >= M:
    ans = 0
else:
    for i in range(1,M):
        arr[i-1] = (abs(X[i-1]-X[i]))
    #print(arr)
    arr.sort()
    ans = sum(arr[0:M-N])
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 = (int(i) for i in input().split())  
x = [int(i) for i in input().split()]  

if m > 1:
    x_diff = []
    for i in range(m-1):
        x_diff.append(x[i+1] - x[i])
else:
    x_diff = [0]

for i in range(n-1):
    max_num = max(x_diff)
    max_index = x_diff.index(max_num)
    x_diff[max_index] = 0

print(sum(x_diff))

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

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

for i in range(n-1):
    max_num = max(x_diff)
    max_index = x_diff.index(max_num)
    x_diff[max_index] = 0

print(sum(x_diff))

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

if m > 1:
    x_diff = []
    for i in range(m-1):
        x_diff.append(x[i+1] - x[i])
else:
    x_diff = [0]

if n > 1:
    x_diff = sorted(x_diff)[:-(n-1)]

print(sum(x_diff))

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())
Xs = list(map(int,input().split()))
if len(Xs) <= N:
    print(0)
else:
    Xs.sort()
    Xdivs = []
    for i in range(M-1):
        Xdivs.append(Xs[i+1]-Xs[i])
    Xdivs.sort()
    print(sum(Xdivs[0:M-N+1]))

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

N,M = map(int,input().split())
Xs = list(map(int,input().split()))
if len(Xs) <= N:
    print(0)
else:
    Xs.sort()
    Xdivs = []
    for i in range(M-1):
        Xdivs.append(Xs[i+1]-Xs[i])
    Xdivs.sort()
    print(sum(Xdivs[: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):
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
x = []
for i in range(M - 1):
    x += [X[i + 1] - X[i]]
x.sort()
ans = sum(x[:M-N])
print(x)

N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
x = []
if N >= M:
    ans = 0
else:
    for i in range(M - 1):
        x += [X[i + 1] - X[i]]
    x.sort()
    ans = sum(x[: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 = map(int, input().split())
x = list(map(int, input().split()))

xSort = sorted(x)

dif = [0] * (m - 1)
for i in range(m - 1):
    dif[i] = xSort[i + 1] - xSort[i]
ans = sum(dif)

if (n == 1 or m == 1):
    print(ans)
else:
    tar = len(dif) - n
    difSort = sorted(dif)
    difS_2 = difSort[:tar]
    ans = sum(difS_2)
    print(ans)
'''  
    for j in range(n - 1):
        tar = j + 1
        tarInd = tar * -1
        tarVal = sorted(dif)[tarInd]
        ans -= tarVal
'''
# print(ans)
# >>>TLE
#



'''
  import numpy as np
  difArray = np.array(dif)
  difIndex = difArray.argsort()

  for i in range(n - 1):
    tar = m - i
    maxIndex = difIndex[tar]
    maxVal = diff
'''


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

xSort = sorted(x)

dif = [0] * (m - 1)
for i in range(m - 1):
    dif[i] = xSort[i + 1] - xSort[i]
ans = sum(dif)

if (n == 1 or m == 1):
    print(ans)

elif (n >= m):
    print('0')
else:
    tar = len(dif) - n + 1
    difSort = sorted(dif)
    difS_2 = difSort[:tar]
    ans = sum(difS_2)
    print(ans)
'''  
    for j in range(n - 1):
        tar = j + 1
        tarInd = tar * -1
        tarVal = sorted(dif)[tarInd]
        ans -= tarVal
'''
# print(ans)
# >>>TLE
#



'''
  import numpy as np
  difArray = np.array(dif)
  difIndex = difArray.argsort()

  for i in range(n - 1):
    tar = m - i
    maxIndex = difIndex[tar]
    maxVal = diff
'''


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()
D = [abs(X[i+1] - X[i]) for i in range(M-1)]
if N >= M:
    print(X[-1] - X[0] - sum(sorted(D)[-(N-1):][::-1]))
else:
    print(0)

import sys
 


 
N,M,*X = map(int, open(0).read().split())
 


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

import sys




# N,M,*X = map(int, open(0).read().split())



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

X.sort()
ans = []
for i in range(M-1):
    ans.append(abs(X[i+1] - X[i]))

print(X[-1] - X[0] - sum(sorted(ans)[::-1][:N-1]))

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

Verdicts: Wrong Answer

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

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]



def main(N, M, Xm):
    
    if N >= M:
        print(0)
        return
    
    Xm.sort()
    
    if N == 1:
        d = Xm[M-1] - Xm[0]
        print(d)
        return
    
    
    Dm = [Xm[i] - Xm[i-1] for i in range(1, M)]
    
    Dm.sort()
    print(Dm)
    
    
    
    
    
    
    d = 0
    for i in range(M-N):
        d += Dm[i]
    print(d)

N, M = i2nn()
Xm = i2nn()
main(N, M, Xm)




import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]



def main(N, M, Xm):
    
    if N >= M:
        print(0)
        return
    
    Xm.sort()
    
    if N == 1:
        d = Xm[M-1] - Xm[0]
        print(d)
        return
    
    
    Dm = [Xm[i] - Xm[i-1] for i in range(1, M)]
    
    Dm.sort()
    
    
    
    
    
    
    d = 0
    for i in range(M-N):
        d += Dm[i]
    print(d)

N, M = i2nn()
Xm = i2nn()
main(N, M, Xm)




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()))
X.sort()
print(X)
sub = [0 for i in range(m)]
for i in range(m):
    if i == m-1:
        sub[i]=0
    else:
        sub[i] = X[i+1]-X[i]
print(sub)

ans = sum(sorted(sub)[:m-n+1])
if n>= m:
    ans = 0
print(ans)
# print("slip list is ", skip_list)
# print("sub List is ", sub)

n, m = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
# print(X)
sub = [0 for i in range(m)]
for i in range(m):
    if i == m-1:
        sub[i]=0
    else:
        sub[i] = X[i+1]-X[i]
# print(sub)

ans = sum(sorted(sub)[:m-n+1])
if n>= m:
    ans = 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 = map(int,input().split())

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

sa = []

for i in range(M-1):
  a = List[i+1] - List[i]
  sa.append(a)
  
sa.sort()

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

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

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

sa = []

for i in range(M-1):
  a = List[i+1] - List[i]
  sa.append(a)
  
sa.sort()
l = len(sa)

if N >= M:
  print(0)
else:
  print(sum(sa[:l-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 = [int(n) for n in input().split()]
 X = sorted([int(n) for n in input().split()])

 if N >= M:
     print(0)
 else:
     diff = []
     for i in range(len(X) - 1):
         diff.append(X[i+1] - X[i])

     diff = list(reversed(sorted(diff)))
     s = 0

     for i in range(N - 1):
         s += diff[i]
     answer = X[-1] - X[0] - s
     print(answer)

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

answer = 0

if N >= M:
    pass
else:
    diff = []
    for i in range(len(X) - 1):
        diff.append(X[i+1] - X[i])

    diff = list(reversed(sorted(diff)))
    s = 0
    for i in range(N - 1):
        s += diff[i]
    answer = X[-1] - X[0] - s

print(answer)

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 = sorted(set(map(int, input().split())))
t = []
for i, j in zip(x, x[1:]):
    t += [i - j]
t = sorted(t, reverse=True)
print(sum(t[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: 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):
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

N,M = [int(x) for x in input().split()]
xls = [int(x) for x in input().split()]
dls = [xls[i+1]-xls[i] for i in range(M-1)]
if N >= M:
    ans = 0


print(ans)

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

N,M = [int(x) for x in input().split()]
xls = [int(x) for x in input().split()]
dls = [xls[i+1]-xls[i] for i in range(M-1)]
if N >= M:
    ans = 0
else:
    dls.sort()
    ans = sum(dls[0:M-N])

print(ans)

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

N,M = [int(x) for x in input().split()]
xls = [int(x) for x in input().split()]
xls.sort()
dls = [xls[i+1]-xls[i] for i in range(M-1)]
if N >= M:
    ans = 0
else:
    dls.sort()
    ans = sum(dls[0:M-N])

print(ans)

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 = input().split()
N = int(N)
M = int(M)

def diffculc(st, ed):
    if ed < st:
        tmp = ed
        ed = st
        st = tmp
    if st < 0 and ed < 0:
        diff = abs(st - ed)
    elif -1 < st and ed < 0:
        diff = abs(ed - st)
    elif st < 0 and -1 < ed:
        diff = abs(st - ed)
    elif -1 < st and -1 < ed:
        diff = ed - st
    return diff

xList = [int(x) for x in input().split()]
sortedList = sorted(xList)


diffcache = {}
diff = 0
for i, x in enumerate(sortedList):
    if i == len(sortedList) - 1:
        break
    diffcache[i] = diffculc(sortedList[i+1], x)

rangeset = []
counter = 0
for k, v in sorted(diffcache.items(), key=lambda x: -x[1]):
    if counter == N - 1:
        break
    diffcache.pop(k)
    counter = counter + 1

result = 0
for k,v in diffcache:
    result = result + v
print(result)

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

def diffculc(st, ed):
    if ed < st:
        tmp = ed
        ed = st
        st = tmp
    if st < 0 and ed < 0:
        diff = abs(st - ed)
    elif -1 < st and ed < 0:
        diff = abs(ed - st)
    elif st < 0 and -1 < ed:
        diff = abs(st - ed)
    elif -1 < st and -1 < ed:
        diff = ed - st
    return diff

xList = [int(x) for x in input().split()]
sortedList = sorted(xList)


diffcache = {}
diff = 0
for i, x in enumerate(sortedList):
    if i == len(sortedList) - 1:
        break
    diffcache[i] = diffculc(sortedList[i+1], x)

rangeset = []
counter = 0
for k, v in sorted(diffcache.items(), key=lambda x: -x[1]):
    if counter == N - 1:
        break
    diffcache.pop(k)
    counter = counter + 1

result = 0
for k,v in diffcache.items():
    result = result + v
print(result)

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

n, m = map(int, input().split())
x = sorted([int(i) for i in input().split()])
diff_x = [x[i + 1] - x[i] for i in range(m - 1)]
diff_x.sort(reverse=True)
if n >= m:
    print(0)
else:
    print((x[m - 1] - x[0]) - sum(diff_x[0:n]))

n, m = map(int, input().split())
x = sorted([int(i) for i in input().split()])
diff_x = [x[i + 1] - x[i] for i in range(m - 1)]
diff_x.sort(reverse=True)
if n >= m:
    print(0)
else:
    print((x[m - 1] - x[0]) - sum(diff_x[0: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):
from sys import sys
n, m, *x = map(int, stdin.read().split())
x.sort()
y = [x[i] - x[i - 1] for i in range(1, m)]
y.sort()
print(sum(y[:-n]) if n < m else 0)


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


from sys import stdin
n, m, *x = map(int, stdin.read().split())
x.sort()
y = [x[i] - x[i - 1] for i in range(1, m)]
y.sort()
print(sum(y[:-n]) if n < m else 0)


from sys import stdin
n, m, *x = map(int, stdin.read().split())
x.sort()
y = [x[i] - x[i - 1] for i in range(1, m)]
y.sort()
print(sum(y[:m - n]) if n < m else 0)


Verdicts: Runtime Error

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 = (int(i) for i in input().split())  
X = [int(i) for i in input().split()] 

s= 0
if N >= M:
    print(0)
else
    X.sort()
    for i in range(M-1):
        lg_bw_x[i] = X[i+1] - X[i]
    for i in range(M-N-1):
        s = s+lg_bw_x[i]
    print(s)

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

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

N, M = (int(i) for i in input().split())  
X = [int(i) for i in input().split()] 
lg_bw_x = [] 
s= 0
if N >= M:
    print(0)
else:
    X.sort()
    for i in range(M-1):
        lg_bw_x.append(X[i+1] - X[i])
    lg_bw_x.sort()
    for j in range(M-N):
        s = s+lg_bw_x[j]
    print(s)

Verdicts: Runtime Error

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(reverse = True)
dis = []
div = 0
for i in range(m - 1):
    dis.append(X[i + 1] = X[i])
dis.sort(Reverse = True)
for i in range(n - 1):
    div += dis[i]
print(sum(dis) - div)

n,m = map(int,input().split(' '))
if n >= m:
    print(0)
else:
    X = list(map(int,input().split(' ')))
    X.sort()
    dis = []
    for i in range(m - 1):
        dis.append(X[i + 1] - X[i])
    dis.sort(reverse = True)
    div = 0
    total = X[m - 1] - X[0]

    for i in range(n - 1):
        div += dis[i]
    print(total - div)

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=[int(i) for i in input().split()]
X=[int(i) for i in input().split()]
X.sort()
rui=[]
for i in range(len(X)-1):
  rui.append(X[i+1]-X[i])
rui.sort()
print(sum(rui[0:-(N-1)]))N,M=[int(i) for i in input().split()]
X=[int(i) for i in input().split()]
X.sort()
rui=[]
for i in range(len(X)-1):
  rui.append(X[i+1]-X[i])
rui.sort()
print(sum(rui[0:-(N-1)]))

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

N,M=[int(i) for i in input().split()]
X=[int(i) for i in input().split()]
X.sort()
rui=[]
for i in range(len(X)-1):
  rui.append(X[i+1]-X[i])
rui.sort()
if N==1:
  print(sum(rui))
elif M>=N:
  print(sum(rui[0:-(N-1)]))
else:
  print(0)

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

if(s[0] >= s[1]):
  print(0)
else:
  t.sort()
  u=[]
  for i in range(s[1]-1):
    u.append(t[i+1]-t[i])
  u.sort()
  print(u)  
  total=0
  for i in range(s[1]-s[0]):
    total+=u[i]
  print(total)

s = list(map(int, input().split()))
t = list(map(int, input().split()))

if(s[0] >= s[1]):
  print(0)
else:
  t.sort()
  u=[]
  for i in range(s[1]-1):
    u.append(t[i+1]-t[i])
  u.sort()
  total=0
  for i in range(s[1]-s[0]):
    total+=u[i]
  print(total)

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
N,M=map(int,input().split(" "))

A=list(sorted(map(int,input().split(" "))))
L=np.array([A[s]-A[s+1] for s in range(M-1)])

if M<=N:
    print(0)

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

A=list(map(int,input().split(" ")).sort())
print(A)

import numpy as np
N,M=map(int,input().split(" "))

A=list(sorted(map(int,input().split(" "))))
L=np.array([A[s]-A[s+1] for s in range(M-1)])

if M<=N:
    print(0)

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

A=list(map(int,input().split(" ")))
A=sorted(A)
L=[A[s]-A[s+1] for s in range(M-1)]

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

from numpy import*
n,m,*x=map(int,open(0).read().split())
x=sorted(x)
x=[x[i+1]-x[i]for i in range(m-1)]
print(int(sum(sorted(x)[::-1][n-1:])))

Verdicts: Wrong Answer

Runtime Error

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()))
n=[]
ans=0
if n>=m:
  print(0)
else:
  x.sort()
  for i in range(n-1):
    n.append(x[i+1]-x[i])
  n.sort(reverse=True)
  for j in range(n-1):
    ans+=n[i]
print(ans)

n,m=map(int,input().split())
x=list(map(int,input().split()))
l=[]
x.sort()
for i in range(1,len(x)):
  l.append(abs(x[i]-x[i-1]))
l.sort()
print(sum(l)-l[-1]-l[-2])

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

n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
n=[]
if n>m:
  print(0)
  exit()
for i in range(1,len(x)):  
  for j in range(i,len(x)):
    n.append(abs(x[0]-x[i-1])+abs(x[i]-x[j-1])+abs(x[j]-x[-1]))
print(min(n))


n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
n=[]
if n>,:
  print(0)
  exit()
for i in range(1,len(x)):  
  for j in range(i,len(x)):
    n.append(abs(x[0]-x[i-1])+abs(x[i]-x[j-1])+abs(x[j]-x[-1]))
print(min(n))


n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
l=[]
if n>m:
  print(0)
  exit()
for i in range(1,len(x)):  
  for j in range(i,len(x)):
    l.append(abs(x[0]-x[i-1])+abs(x[i]-x[j-1])+abs(x[j]-x[-1]))
print(min(n))


n,m=map(int,input().split())
x=list(map(int,input().split()))
l=[]
ans=0
if n<m:
  x.sort()
  for i in range(m-1):
    l.append(x[i+1]-x[i])
  l.sort()
  for j in range(m-n):
    ans+=l[j]
print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

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

n,m=map(int,input().split())
X=sorted(list(map(int,input().split())))
ans=[]
if m<n:
  print(0)
  exit()
for i in range(m-1):
  ans.append(X[i+1]-X[i])
ans=sorted(ans)
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):
# -*- coding: utf-8 -*-
n,m = map(int,input().split())
xlist = list(map(int,input().split()))

xlist.sort()
ylist=[]

for i in range(1,m):
    ylist.append(xlist[i]-xlist[i-1])

ylist.sort()
a=0
for i in range(1,m-n):
    a+=ylist[i]
print(a)



# -*- coding: utf-8 -*-
n,m = map(int,input().split())
xlist = list(map(int,input().split()))

xlist.sort()
ylist=[]

for i in range(1,m):
    ylist.append(xlist[i]-xlist[i-1])

ylist.sort()
a=0
for i in range(0,m-n):
    a+=ylist[i]
print(a)



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

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

X.sort() # O(MlogM)

# O(M)
D = []
for i in range(M-1):
  D.append(X[i+1] - X[i])

D.sort() # O(MlogM)

print(sum(D[:M-N+1])) # O(M)


import sys
n, m = map(int, input().split())
X = list(map(int, input().split()))
if n >= m:
  print(0)
  sys.exit()

print(X)
X.sort()
print(X)

L = []
for i in range(m-1):
  L.append(X[i+1] - X[i])
print(L)
L.sort(reverse=True)
print(L)
print((X[m-1]-X[0]) - (sum(L[0:n-1])))


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

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

X.sort() # O(MlogM)

# O(M)
D = []
for i in range(M-1):
  D.append(X[i+1] - X[i])

D.sort() # O(MlogM)

print(sum(D[:M-N+2])) # O(M)


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

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

X.sort() # O(MlogM)

# O(M)
D = []
for i in range(M-1):
  D.append(X[i+1] - X[i])

D.sort() # O(MlogM)

print(sum(D[:M-N])) # O(M)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted