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):
X.sort()

memo = dict()
def get_min(n,x):
    key = str((n,x))
    tmp = memo.get(key,None)
    if tmp != None:
        return tmp
    if x == []:
        tmp = 10**8
        memo[key] = tmp
        return tmp
    elif len(x) == 1:
        memo[key] = 0
        return 0
    x0 = x[0]
    if n == 1:
        tmp = x[-1]-x0
        memo[key] = tmp
        return tmp
    tmp = min([y - x0 + get_min(n-1,x[i+1:]) for i,y in enumerate(x)])
    memo[key] = tmp
    return tmp
if N >= M:
    print(0)
else:
    print(get_min(N,X))

N,M = map(int,input().split())
X = sorted(list(map(int,(input().split()))))
dif_X = sorted([X[i+1]-x for i,x in enumerate(X[:-1])])
print(sum(dif_X[:max(0,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):
N, M = map(int, input().split())
if N >= M:
  	print(0)
else:
	X = list(map(int, input().split()))
	X = sorted(X)
	L = []
	for i in range(0, M-1):
    	L.append(X[i+1] - X[i])
	L = sorted(L, reverse = True)
	S = 0
	for i in range(N-1):
    	S += L[i]
	res = X[M-1] - X[0] - S
	print(res)

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

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()
count=[]
sum=0
if n<m:
  for i in range(M):
    if i != 0:
      count.append(X[i]-get)
      sum+=count[i-1]
    get=X[i]
  count.sort(reverse=True)
  if count != []:
    for i in range(N-1):
      sum-=count[i]
print(sum)

N,M=map(int,input().split())
X=[int(i) for i in input().split()]
X.sort()
count=[]
sum=0
if n<=m:
  for i in range(M):
    if i != 0:
      count.append(X[i]-get)
      sum+=count[i-1]
    get=X[i]
  count.sort(reverse=True)
  if count != []:
    for i in range(N-1):
      sum-=count[i]
print(sum)

n,m = map(int,input().split())
x = [int(i) for i in input().split()]
x.sort()
xx = []
for i in range(len(x)-1):
  xx.append(abs(x[i]-x[i+1]))
xx.sort()
print(sum(xx[:-(n-1)])if n!=1 else sum(xx))


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):
try:
    N, M = map(int, input().split())
    Xi = [int(x) for x in input().split()]

    if N < 1 or N > 10**5:
        exit()
    if M < 1 or M > 10**5:
        exit()
    if M != len(Xi):
        exit()
    for i in Xi:
        if Xi[i] < -10**5 or Xi[i] > 10**5:
            exit()
    
except ValueError:
    exit()



try:
    N, M = map(int, input().split())
    Xi = [int(x) for x in input().split()]

    if N < 1 or N > 10**5:
        exit()
    if M < 1 or M > 10**5:
        exit()
    if M != len(Xi):
        exit()
    for i in Xi:
        if i < -10**5 or i > 10**5:
            exit()
    Xi = sorted(Xi)

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

    a = sorted(a, reverse=True)
    s = 0
    # print(a)
    for i in range(N-1):
        # print(a[0])
        a.pop(0)

    for i in a:
        s += abs(i)
    print(s)
except ValueError:
    exit()
except IndexError:
    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.sort()
s = [0] * (m-1)
for i in range(m-1):
  s[i] = x[i+1] - x[i]
s.sort(reverse=1)
if n != 1:
  print(sum(s[:-n+1]))
else:
  print(sum(s))

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

x.sort()

y = []
for i in range(0, m - 1):
    print(x[i+1], x[i])
    y.append(x[i + 1] - x[i])

y.sort()

s = sum(y[0:m - n])
print(s)


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

x.sort()

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

y.sort()

s = 0
if m > n:
    s = sum(y[0:m - n])
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 = map(int,input().split())
X = list(map(int,input().split()))
X = sorted(X,reverse = False)


if len(X) == 1:
    print(0)
else:
    dist = []
    for i in range(1,M):
        dist.append(X[i]-X[i-1])
    dist = sorted(dist,reverse = False)
    print(dist)
    
    for k in range(N-1):
        dist.pop()
        if len(dist) == 0:
            break
    print(sum(dist))


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


if len(X) == 1:
    print(0)
else:
    dist = []
    for i in range(1,M):
        dist.append(X[i]-X[i-1])
    dist = sorted(dist,reverse = False)
    
    for k in range(N-1):
        dist.pop()
        if len(dist) == 0:
            break
    print(sum(dist))

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):
spots_and_people = input().split()
spot_values = input().split()

N_spot = int(spots_and_people[1])
N_people = int(spots_and_people[0])

spot_values = [ int(value) for value in spot_values ]
spot_values.sort()

line_length = [ spot_values[i+1] - spot_values[i] for i in range(N_spot-1) ]
line_length.sort()
print(line_length)

if N_spot == N_people:
  travel = 0
  
for i in range(N_people-1):
  line_length.pop(-1)
  

print(line_length)

travel = sum(line_length)

print(travel)

spots_and_people = input().split()
spot_values = input().split()

N_spot = int(spots_and_people[1])
N_people = int(spots_and_people[0])

spot_values = [ int(value) for value in spot_values ]
spot_values.sort()

line_length = [ spot_values[i+1] - spot_values[i] for i in range(N_spot-1) ]
line_length.sort()


if N_spot <= N_people:
	travel = 0

else:
	for i in range(N_people-1):
  		line_length.pop(-1)
  

	travel = sum(line_length)

print(travel)

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 = list(map(int, input().split()))
lst = sorted(set(map(int, input().split())))
print(lst)
dis = []
for i, j in zip(lst, lst[1:]):
    dis += [j - i]
    print(dis)
print(sum(sorted(dis, reverse=True)[n - 1:]))

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

dis = []
for i, j in zip(lst, lst[1:]):
    dis += [j - i]
    
print(sum(sorted(dis, reverse=True)[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()))

# print(n, m, x)

# #%%
# n, m =2, 5
# x = [10, 12, 1, 2, 14]


#%%
x.sort()

#%%




#%%

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


#%%
diff_list.sort()


#%%
print(x[-1] - x[0] - sum(diff_list[-(n-1):])

#%%


#%%


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

# print(n, m, x)

# #%%
# n, m =2, 5
# x = [10, 12, 1, 2, 14]


#%%
x.sort()

#%%




#%%

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


#%%
diff_list.sort()


#%%
print(x[-1] - x[0] - sum(diff_list[-(n-1):])

#%%


#%%


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

# print(n, m, x)

# #%%
# n, m =2, 5
# x = [10, 12, 1, 2, 14]


#%%
x.sort()

#%%




#%%

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


#%%
diff_list.sort()


#%%
if n-1>0:
    print(sum(diff_list[:-(n-1))])
else:
    print(0)    

#%%


#%%


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

print(n, m, x)

# #%%
# n, m =2, 5
# x = [10, 12, 1, 2, 14]


#%%
x.sort()

#%%
if m == n:
    print(0)



#%%

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


#%%
diff_list.sort()


#%%
print(sum(diff_list[:-(n-1)]))

#%%


#%%


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

# print(n, m, x)

# #%%
# n, m =2, 5
# x = [10, 12, 1, 2, 14]


#%%
x.sort()

#%%




#%%

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


#%%
diff_list.sort()


#%%
print(diff_list[:-(max(0,n-1))])

#%%


#%%


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

# print(n, m, x)

# #%%
# n, m =2, 5
# x = [10, 12, 1, 2, 14]


#%%
x.sort()

#%%




#%%

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


#%%
diff_list.sort()


#%%
if n-1>0:
    print(sum(diff_list[:-(n-1)]))
else:
    print(sum(diff_list))    

#%%


#%%


Verdicts: Runtime Error

Runtime Error

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=input().split()
n=int(n)
m=int(m)
a = input().split()
for i in range(m):
  a[i]=int(a[i])
  
if n>=m :
  sum=0
else:
  b=[]
  sum=0
  for i in range(m):
    b+=[a[i+1]-a[i]]
  b.sort().reverse()
  for i in range(N-1):
    sum+=b[i]
print(sum)
  

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


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


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


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

x_list.sort()
ans = 0

margin = [0] * (M - 1)
f = x_list[0]
for i in range(1, M):
    margin[i - 1] = x_list[i] - f
    f = x_list[i]
margin = sorted(enumerate(margin), key=lambda x: -x[1])

cnt = [0]
for i, v in margin:
    cnt.append(i + 1)
    if len(cnt) == N:
        break

start = 0
prev = x_list[0]
for i, c in enumerate(cnt[1:]):
    for j in range(start, c):
        ans += x_list[j] - prev
        prev = x_list[j]
    start = c
    prev = x_list[c]
last = cnt[-1]
for i in range(last, M):
    if i == last:
        prev = x_list[i]
    else:
        ans += x_list[i] - prev
        prev = x_list[i]


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

x_list.sort()
ans = 0

margin = [0] * (M - 1)
f = x_list[0]
for i in range(1, M):
    margin[i - 1] = x_list[i] - f
    f = x_list[i]
margin = sorted(enumerate(margin), key=lambda x: (-x[1], x[0]))

cnt = [0]
for i, v in margin:
    cnt.append(i + 1)
    if len(cnt) == N:
        break

start = 0
prev = x_list[0]
for i, c in enumerate(cnt[1:]):
    for j in range(start, c):
        ans += x_list[j] - prev
        prev = x_list[j]
    start = c
    prev = x_list[c]
last = cnt[-1]
for i in range(last, M):
    if i == last:
        prev = x_list[i]
    else:
        ans += x_list[i] - prev
        prev = x_list[i]


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

margin = []
prev = x_list[0]
for i in range(1, M):
    margin.append(x_list[i] - prev)
    prev = x_list[i]

margin.sort(reverse=True)
print(x_list[-1] - x_list[0] - sum(margin[: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):
N, M = [int(x) for x in input().split(' ')]
XP = [int(x) for x in input().split(' ')]
XP.sort()
D = [0] * (len(XP)-1)
for x in range(len(XP)-1):
    d = XP[x+1] - XP[x]
    D[x] = d
D.sort()
s = 0
for i in range(len(D) - N + 1):
    print(i,D[i])
    s += D[i]
print(s)

N, M = [int(x) for x in input().split(' ')]
XP = [int(x) for x in input().split(' ')]
XP.sort()
D = [0] * (len(XP)-1)
for x in range(len(XP)-1):
    d = XP[x+1] - XP[x]
    D[x] = d
D.sort()
s = 0
for i in range(len(D) - N + 1):
    s += D[i]
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=map(int,input().split())
lst=list(map(int,input().split()))
sort(lst)
sum_1=sum(lst)
D=[]
for i in range(1,M):
    D.append(lst[i]-lst[i-1])
sort(D,reverse=True)
sum_2=0
for i in range(N-1):
    sum_2+=D[i]
ans=0
ans=sum_1-sum_2
print(ans)


N,M=map(int,input().split())
if N>M:
    print(0)
    exit()
lst=list(map(int,input().split()))
lst.sort()
sum_1=max(lst)-min(lst)
D=[]
for i in range(1,M):
    D.append(lst[i]-lst[i-1])
D.sort(reverse=True)
sum_2=0
for i in range(N-1):
    sum_2+=D[i]
ans=0
ans=sum_1-sum_2
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())
l = [int(x) for x in input().split()]

l.sort()

gap = [l[i]-l[i-1] for i in range(1,len(l))]

gap = gap.sort()

print(sum(gap[:-(m-1)]))

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

if(n>=m):
  print('0')
  exit(0)
l.sort()
 
gap = [l[i+1]-l[i] for i in range(m-1)]
 
gap.sort()

print(sum(gap[: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):
N,M = map(int,input().split())
X = list(map(int,input().split()))
x = []
count = 0
ans = 0
X.sort()
if N >= M:
  print(0)
for i in range(M-1):
  x.append(abs(X[i]-X[i+1]))
xx = sorted(x,reverse=True)
for j in range(N//2):
  xx.pop(j)
ans = xx[-1] - xx[0]
print(ans)

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

ans = 0

if N >= M:
  pass
else:
  X.sort()
  dist = []

  for i in range(1,M):
    dist.append(abs(X[i]-X[i-1]))
  dist = sorted(dist, reverse= True)

  ans = sum(dist[N-1:])

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

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

distance = [0]*(M-1)
distance[0] = x[1]-x[0]
for i in range(0,M-1):
	distance[i] = x[i+1]-x[i]

distance_sorted = sorted(distance)
print(distance_sorted)
ans = 0
for i in range(0,M-N):
	ans += distance_sorted[i]

print(ans)




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

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

distance = [0]*(M-1)
distance[0] = x[1]-x[0]
for i in range(0,M-1):
	distance[i] = x[i+1]-x[i]

distance_sorted = sorted(distance)
ans = 0
for i in range(0,M-N):
	ans += distance_sorted[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):
print(d)


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(1, M)])
ans = 0
c = 0
for i in d:
    if c > M - N - 1:
        break
    ans += i
    c += 1
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())
if n >= m :
  print(0)
else:
  ls=[int(s) for s in input().split()]
  ls.sort()
  d=[ls[i+1]-ls[i] for i in range(m-1)]
  d.sort()
  print(sum(d[:n-m]))


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


Verdicts: Wrong Answer

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

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

Verdicts: Runtime Error

Accepted
Problem: We will play a one-player game using a number line and N pieces.  First, we place each of these pieces at some integer coordinate.  Here, multiple pieces can be placed at the same coordinate.  Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move:  **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1.  Note that the coordinates where we initially place the pieces are already regarded as visited.  Find the minimum number of moves required to achieve the objective.

Submission attempts (in order):
n, m = map(int, input().split())
x = [int(i) for i in input().split()]
if n >= m:
    print(0)
    exit()
x.sort()
dis = [abs(x[i+1] - x[i]) for i in range(m-1)]
dis.sort()
for _ in range(n-1): dis.pop(-1)
print(dis)
print(sum(dis))

n, m = map(int, input().split())
x = [int(i) for i in input().split()]
if n >= m:
    print(0)
    exit()
x.sort()
dis = [abs(x[i+1] - x[i]) for i in range(m-1)]
dis.sort()
for _ in range(n-1): dis.pop(-1)
print(sum(dis))

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


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

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

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


import sys

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

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


import sys

N, M = map(int, input().split())
if N >= M:
    print(0)
    sys.exit(0)

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

distance_list = [b - a for a, b in zip(X, X[1:])]
distance_list.sort()

if N != 1:
    print(sum(distance_list[:-N+1]))
else:
    print(sum(distance_list))


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

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

d = []
for i in range(M-1):
    d.append(abs(l[i+1]-l[i]))
d = list(sorted(d))
print(d)
while N != 1 and len(d) !=0:
    del d[len(d)-1]
    N -= 1
sum = 0
if len(d) >= 1:
    for i in range(len(d)):
        sum += d[i]
print(sum)


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

d = []
for i in range(M-1):
    d.append(abs(l[i+1]-l[i]))
d = list(sorted(d))
while N != 1 and len(d) !=0:
    del d[len(d)-1]
    N -= 1
sum = 0
if len(d) >= 1:
    for i in range(len(d)):
        sum += d[i]
print(sum)


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()])
l=sorted([max(x[i]-x[i+1],-x[i]+x[i+1]) for i in range(m-1)])
print([sum(l[:-n+1]),0][n<m])

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

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

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: We will play a one-player game using a number line and N pieces.  First, we place each of these pieces at some integer coordinate.  Here, multiple pieces can be placed at the same coordinate.  Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move:  **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1.  Note that the coordinates where we initially place the pieces are already regarded as visited.  Find the minimum number of moves required to achieve the objective.

Submission attempts (in order):
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
diff = []
if n < m:
    print(0)
    exit()
for i in range(1, m):
    diff.append(x[i] - x[i - 1])
diff.sort()
print(sum(diff[:m-n]))


n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
diff = []
if M <= N:
    print(0)

for i in range(1, m):
    diff.append(x[i] - x[i - 1])
diff.sort()
print(sum(diff[:m-n]))


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


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: We will play a one-player game using a number line and N pieces.  First, we place each of these pieces at some integer coordinate.  Here, multiple pieces can be placed at the same coordinate.  Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move:  **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1.  Note that the coordinates where we initially place the pieces are already regarded as visited.  Find the minimum number of moves required to achieve the objective.

Submission attempts (in order):
def main():
  N, M = map(int, input().split())
  X = list(map(int, input().split()))
  
  X = sorted(X)
  print(X)
  X = sorted([X[i+1]-X[i] for i in range(M-1)], reverse=True)
  print(X)
  print(sum(X[N-1:]))


main()

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


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):
#!/usr/bin/env python3
# sys.stdin.readline()
import numpy as np

import math

n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
B = [-A[i]+A[i+1] for i in range(m-1)]
B.sort()
print(B,sum(B[0:max(m-n,0)]))

#!/usr/bin/env python3
# sys.stdin.readline()
import numpy as np

import math

n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
B = [-A[i]+A[i+1] for i in range(m-1)]
B.sort()
print(sum(B[0:max(m-n,0)]))

Verdicts: Wrong Answer

Accepted
Problem: We will play a one-player game using a number line and N pieces.  First, we place each of these pieces at some integer coordinate.  Here, multiple pieces can be placed at the same coordinate.  Our objective is to visit all of the M coordinates X_1, X_2, ..., X_M with these pieces, by repeating the following move:  **Move** : Choose a piece and let x be its coordinate. Put that piece at coordinate x+1 or x-1.  Note that the coordinates where we initially place the pieces are already regarded as visited.  Find the minimum number of moves required to achieve the objective.

Submission attempts (in order):
import sys

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

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

    X = sorted(X)

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

    kukan = sorted(kukan, reverse=True)

    jogai = 0
    for j in range(N-1):
        jogai += kukan[j]

    print(X[M-1] - X[0] - jogai)

    print(kukan)

main()

import sys

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

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

    X = sorted(X)

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

    kukan = sorted(kukan, reverse=True)

    jogai = 0
    for j in range(N-1):
        jogai += kukan[j]

    print(X[M-1] - X[0] - jogai)

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):
nm = [int(i) for i in input().split()]
points = sorted([int(i) for i in input().split()])
n, m = nm[0], nm[1]

if n >= m:
    print(0)
elif n == 1:
    print(max(points) - min(points))
else:
    list_diff = [points[i+1] - points[i] for i in range(m-1)]
    list_th = []
    for i in range(n-1):
        max_index = list_diff.index(max(list_diff))
        list_th.append(max_index)
        list_diff[max_index] = 0
        
    x = points[0]
    th = 0
    count = 0
    print(list_th)
    while x < points[-1]:
        if x == points[list_th[th]]:
            x = points[list_th[th]+1]
            th += 1
        else:
            x += 1
            count += 1
            if x == points[-1]:
                break
    print(count)

n, m = list(map(int, input().split()))
xxx = list(map(int, input().split()))
 
if n >= m:
    print(0)
    exit()
xxx.sort()
ddd = [b - a for a, b in zip(xxx, xxx[1:])]
ddd.sort()
print(sum(ddd[: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):
N,M = map(int,input().split())
tmpX =list(input().split())
X = [int(s) for s in tmpX]
X.sort()
X_difference=[]
for i in range(M-1):
    X_difference.append(X[i+1]-X[i])
print(X_difference)
X_difference.sort(reverse = True)
del X_difference[0:N-1:]
print(sum(X_difference))

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

X_difference.sort(reverse = True)
del X_difference[0:N-1:]
print(sum(X_difference))

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


n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
diff = sorted([abs(x[i+1] - x[i]) for i in range(len(x)-1)])
print(diff)
print(x[-1] - x[0] - sum(diff[-1:n:-1])) if n < m else print(0)


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

for i in range(m - 3):
  total += y[i]

print(total)

n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
if m > 1:
  y = sorted([x[i + 1] - x[i] for i in range(m - 1)])
total = 0

if m == 1:
  print(0)
elif m == 2 and n == 1:
  print(y[0])
elif m == 2 and n > 1:
  print(0)
else:
  for i in range(m - 3):
    total += y[i]
  print(total)

n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
if m > 1:
  y = sorted([x[i + 1] - x[i] for i in range(m - 1)])
total = 0

if n >= m:
  print(0)
else:
  for i in range(m - n):
    total += y[i]
  print(total)

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

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

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

x.sort()
diff = []
for i in range(m-1):
    diff.append(x[i+1] - x[i])
diff.sort(reverse= True)
ans = sum(diff) - sum(diff[0:n-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):
#C-117
n, m = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
if n >= m:
  print(0)
elif n == 1:
  print(max(x) - min(x))
else:
  x.sort()
  x_diff = []
  for mi in range(m-1):
    x_diff.append(x[mi+1]-x[mi])
  print(x_diff)
  split_list = []
  for ni in range(n-1):
    split_idx = x_diff.index(max(x_diff))
    split_list.append(split_idx)
    x_diff[split_idx] = 0
  split_list.sort()
  print(split_list)
  print(x)
  ans = 0
  ans += x[split_list[0]] - x[0]
  print("ans",ans)
  for ni in range(n-2):
    l = split_list[ni]+1
    r = split_list[ni+1]
    ans += x[r] - x[l]
    print("ans",ans)
  ans += x[-1] - x[split_list[-1]+1]
  print(ans)


#C-117
n, m = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
if n >= m:
  print(0)
elif n == 1:
  print(max(x) - min(x))
else:
  x.sort()
  x_diff = []
  for mi in range(m-1):
    x_diff.append([x[mi+1]-x[mi], mi])
  #print(x_diff)
  x_diff.sort(reverse = True)
  #print(x_diff)
  split_list = []
  for ni in range(n-1):
    split_idx = x_diff[ni][1]
    split_list.append(split_idx)
  split_list.sort()
  #print(split_list)
  #print(x)
  ans = 0
  ans += x[split_list[0]] - x[0]
  #print("ans",ans)
  for ni in range(n-2):
    l = split_list[ni]+1
    r = split_list[ni+1]
    ans += x[r] - x[l]
    #print("ans",ans)
  ans += x[-1] - x[split_list[-1]+1]
  print(ans)


Verdicts: Wrong Answer

Accepted