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

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

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

Verdicts: Runtime Error

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

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



n,m = map(int,input().split())
l = sorted(list(map(int,input().split())))
diff = sorted([l[i+1]-l[i] for i in range(0,m-1)],reverse = True)
print(l[-1]-l[0]-sum(diff[: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=sorted(set(list(map(int,input().split()))))
print(X)
s=[]
for i in range(M-1):s.append(X[i+1]-X[i])
s=sorted(s)
print(sum(s[:N+1]))

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
Import sys
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = []

if m == 1:
    print(0)
    sys.exit()

#x.sort()
list.sort(x)
#print(x)

for i in range(1, m):
    a.append(x[i] - x[i-1])

list.sort(a, reverse=True)
#print(a)

count = max(x) - min(x)
for i in range(n-1):
    if len(a) == 0:
        break
    count -= a[i]

print(count)


import sys
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = []

if m == 1:
    print(0)
    sys.exit()

#x.sort()
list.sort(x)
#print(x)

for i in range(1, m):
    a.append(x[i] - x[i-1])

list.sort(a, reverse=True)
#print(a)

count = max(x) - min(x)
for i in range(n-1):
    if len(a) == 0:
        break
    a.pop()
#    count -= a[i]

#print(count)
print(sum(a))


import sys
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = []

if m == 1:
    print(0)
    sys.exit()

#x.sort()
list.sort(x)
#print(x)

for i in range(1, m):
    a.append(x[i] - x[i-1])

#list.sort(a, reverse=True)
a.sort()
#print(a)

count = max(x) - min(x)
for i in range(n-1):
    if len(a) == 0:
        break
    a.pop()
#    count -= a[i]

#print(count)
print(sum(a))

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

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

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

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

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

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

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

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

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

if n >= m:print(0)
else:
    dist = [abs(x[i+1] - x[i]) for i in range(M-1)]
    dist = sorted(dist)
    print(sum(dif[:-(n-1)]))

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

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

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

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

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

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

Verdicts: Runtime Error

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

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

if N < M:
    mar = [X[i+1] - X[i] for i in range(len(M-1))]
    mar.sort()
    print(sum([mar[i] for i in range(M-N)]))
else:
    print(0)


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

if N <= M:
    mar = [X[i+1] - X[i] for i in range(len(M-1))]
    mar.sort()
    print(sum([mar[i] for i in range(M-N)]))
else:
    print(0)


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

if N < M:
    mar = [abs(X[i+1] - X[i]) for i in range(len(M-1))]
    mar.sort()
    print(sum([mar[i] for i in range(M-N)]))
else:
    print(0)


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

if N < M:
    mar = [abs(X[i+1] - X[i]) for i in range(M-1)]
    mar.sort()
    print(sum([mar[i] for i in range(M-N)]))
else:
    print(0)


Verdicts: Runtime Error

Runtime Error

Runtime Error

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

Submission attempts (in order):
import sys

def split(g, n):
  gl = g[:-1]
  gr = g[1:]
  sub = [[(b - a), i] for a, b, i in zip(gl, gr, range(len(gl)))]
  i = sub.index(max(sub)) + 1
  sub = sorted(sub, key = lambda x: -x[0])
  j = []
  for i in range(n-1):
    j.append(sub[i][1]+1)
  j = sorted(j)
  jl = [0] + j[:-1]
  res = []
  for l, r in zip(jl, j):
    s = g[l:r]
    res.append(s)
  return res


def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  g = [int(a) for a in input().split()]
  g = sorted(g)
  ans = 0
  if N < M:
    sp = split(g, N)
    for s in sp:
      ans += s[-1] - s[0]
  print(ans)


if __name__ == '__main__':
  main()

import sys

def split(g, n):
  gl = g[:-1]
  gr = g[1:]
  sub = [[(b - a), i+1] for a, b, i in zip(gl, gr, range(len(gl)))]
  sub = sorted(sub, key = lambda x: -x[0])
  j = []
  for i in range(n-1):
    j.append(sub[i][1])
  j = sorted(j)
  jl = [0] + j[:-1]
  res = []
  for l, r in zip(jl, j):
    s = g[l:r]
    res.append(s)
  R = j[-1]
  res.append(g[R:])
  print(res)
  return res


def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  g = [int(a) for a in input().split()]
  g = sorted(g)
  ans = 0
  if N < M:
    sp = split(g, N)
    for s in sp:
      if len(s) <= 0:
        continue
      ans += s[-1] - s[0]
  print(ans)


if __name__ == '__main__':
  main()

import sys

def split(g, n):
  gl = g[:-1]
  gr = g[1:]
  sub = [[(b - a), i+1] for a, b, i in zip(gl, gr, range(len(gl)))]
  sub = sorted(sub, key = lambda x: -x[0])
  j = []
  for i in range(n-1):
    j.append(sub[i][1])
  j = sorted(j)
  jl = [0] + j[:-1]
  res = []
  for l, r in zip(jl, j):
    s = g[l:r]
    res.append(s)
  R = j[-1]
  if R < len(g):
    res.append(g[R:])
  print(res)
  return res


def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  g = [int(a) for a in input().split()]
  g = sorted(g)
  ans = 0
  if N < M:
    sp = split(g, N)
    for s in sp:
      ans += s[-1] - s[0]
  print(ans)


if __name__ == '__main__':
  main()

import sys

def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  ans = 0
  if N < M:
    g = [int(a) for a in input().split()]
    g = sorted(g)
    L = g[:-1]
    R = g[1:]
    sub = [b - a for a, b in zip(L, R)]
    sub = sorted(sub)
    ans = sum(sub[:(M-N)])
  print(ans)


if __name__ == '__main__':
  main()

Verdicts: Wrong Answer

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

lx.sort()
dx = []
s = 0

for i in range(len(lx)-1):
  dx.append(lx[i+1]-lx[i])

if n == 1:
  print(lx[m-1]-lx[0])
elif m <= n:
  print(0)
else:
  dx.sort()
  print(dx)
  for i in range(len(dx)-n+1):
    s = s + dx[i]
  print(s)

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

lx.sort()
dx = []
s = 0

for i in range(len(lx)-1):
  dx.append(lx[i+1]-lx[i])

if n == 1:
  print(lx[m-1]-lx[0])
elif m <= n:
  print(0)
else:
  dx.sort()
  for i in range(len(dx)-n+1):
    s = s + dx[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())
a=sorted(list(map(int,input().split())))
b=[]
for i in range(m-1):
  b.append(a[i+1]-a[i])
b.sort()
if n>=m:
  print(0)
else:
  print(sum(b[m-n-1:]))

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


Verdicts: Wrong Answer

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

Submission attempts (in order):


#include <algorithm>
using namespace std;

int main() {
    int N, M; cin >> N >> M;
    vector<int> X(M);
    for (auto& xi : X) cin >> xi;
    sort(X.begin(), X.end());
    vector<int> diff(M - 1);
    for (int i = 0; i < M - 1; i++) {
        diff[i] = abs(X[i] - X[i + 1]);
    }
    sort(diff.begin(), diff.end());
    int res = 0;
    for (int i = 0; i < (M - 1) - (N - 1); i++) {
        res += diff[i];
    }
    cout << res << endl;
    return 0;
}

N, M = map(int, input().split())
X = sorted(map(int, input().split()))
D = sorted(abs(x - y) for x, y in zip(X, X[1:]))
if N > 1:
    print(sum(D[:-(N-1)]))
else:
    print(sum(D))

Verdicts: Runtime Error

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

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

if N >= M:
  print(0)
else:
  X.sort()

  diffs = [0]*(M-1)

  for i in range(M-1):
    diffs[i] = abs(x[i+1] - X[i])

  diffs.sort(key= lambda x: -x[0])
  
  print(sum(diffs[N-1:]))
  
  
  

  
  


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

if N >= M:
  print(0)
else:
  X.sort()

  diffs = [0]*(M-1)

  for i in range(M-1):
    diffs[i] = abs(X[i+1] - X[i])

  diffs.sort(key= lambda x: -x)

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

Verdicts: Runtime Error

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

Submission attempts (in order):
N,M=map(int,input().split())
X=list(map(int,input().split()))
X.sort()
distance=X[M-1]-X[0]
sa=[]
for i in range(M-1):
  sa.append(X[i+1]-X[i])
sa.sort()
sum(sa[:(N-1)*(-1)])

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

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

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

if N >= M:
    print(0)
elif N == 1:
    print(Xs[-1]-Xs[0])
else:
    margin = [Xs[i+1]-Xs[i] for i in range(len(Xs)-1)]
    margin = [(i,x) for i,x in enumerate(margin)]
    point = [x[0] for x in sorted(margin,key=lambda x:x[1],reverse=True)[:N-1]]
    print(point)
    move = 0
    move += Xs[point[0]] - Xs[0]
    for i in range(1,len(point)):
        move += Xs[point[i]] - Xs[point[i-1]+1]
    move += Xs[-1] - Xs[point[-1]+1]
    print(move)


import numpy as np

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

if N >= M:
    print(0)
elif N == 1:
    print(Xs[-1]-Xs[0])
else:
    margin = [Xs[i+1]-Xs[i] for i in range(len(Xs)-1)]
    margin = [(i,x) for i,x in enumerate(margin)]
    point = [x[0] for x in sorted(margin,key=lambda x:x[1],reverse=True)[:N-1]]
    move = 0
    move += Xs[point[0]] - Xs[0]
    for i in range(1,len(point)):
        move += Xs[point[i]] - Xs[point[i-1]+1]
    move += Xs[-1] - Xs[point[-1]+1]
    print(move)

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())))
B=[]

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

    B.sort()
    print(sum(B[:-(N-1)]))



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

if N<=M:
    print(0)
    exit()
else:
    for i in range(M-1):
        B.append(X[i+1]-X[i])

    B.sort()
    print(sum(B[:M-N]))



N,M = map(int,input().split())
X = sorted(list(map(int,input().split())))
#X.sort()
B=[]

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

    B = sorted(B,reverse = True)
    print(sum(B[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):
import heapq
n,m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
x_range = []
cut = [0]
count = 0
for i in range(m-1):
    x_range.append(abs(x[i]-x[i+1]))
h = heapq.nlargest(n-1,x_range)


for i in h:
    cut.append(x_range.index(i)+1)
cut.append(len(x))


for i in range(len(cut)-1):
    sum_range = x[cut[i]:cut[i+1]]
    print(1)
    count += abs(sum_range[0]-sum_range[len(sum_range)-1])
#print(count)


import heapq
n,m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
x_range = []
cut = [0]
count = 0
for i in range(m-1):
    x_range.append(abs(x[i]-x[i+1]))
h = heapq.nlargest(n-1,x_range)


for i in h:
    cut.append(x_range.index(i)+1)
cut.append(len(x))
print(1)



import heapq
n,m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
x_range = []
cut = [0]
count = 0
for i in range(m-1):
    x_range.append(abs(x[i]-x[i+1]))
h = heapq.nlargest(n-1,x_range)
print(1)



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


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(map(int, input().split()))
x_new = sorted(x)
intervals = [0]*(m-1)
for i in range(m-1):
  intervals[i] = x[i+1] - x[i]
c = sorted(intervals, reverse=True)
s = 0
for j in range(n-1):
  s += c[j]

min = sum(intervals) - s
print(s)
  

n,m = map(int,input().split())
x = list(map(int, input().split()))
x_new = sorted(x)
intervals = [0]*(m-1)
for i in range(m-1):
  intervals[i] = abs(x_new[i+1] - x_new[i])
c = sorted(intervals, reverse=True)
s = 0
if n < m:
    for j in range(n-1):
        s += c[j]
    min = sum(intervals) - s
    print(min)
else:
    print(0)

Verdicts: Runtime Error

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

Submission attempts (in order):
list1 = list(map(int, input().split()))
N = list1[0]
M = list1[1]
list2 = list(map(int, input().split()))
list2 = sorted(list2, reverse=True)
# print(list2)
list3 = []
for i in range(len(list2) - 1):
    list3.append(list2[i] - list2[i + 1])
list3 = sorted(list3, reverse=True)
print(list3)
sum = 0
for i in range(N - 1):
    sum = sum + list3.pop(0)
ans = list2[0] - list2[-1] - sum
print(ans)


list1 = list(map(int, input().split()))
N = list1[0]
M = list1[1]
list2 = list(map(int, input().split()))
if list1[0] - list1[1] >= 0:
    print(0)
    exit(0)
list2 = sorted(list2, reverse=True)
# print(list2)
list3 = []
for i in range(len(list2) - 1):
    list3.append(list2[i] - list2[i + 1])
list3 = sorted(list3, reverse=True)
# print(list3)
sum = 0
for i in range(N - 1):
    sum = sum + list3.pop(0)
ans = list2[0] - list2[-1] - sum
print(ans)


Verdicts: Runtime Error

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

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

X_dif = []

excep = 0

if M == 1:
    excep = M1
    
if not excep = M1:
    for i in range(M-1):
        X_dif.append(X[i+1]-X[i])
    
    X_dif.sort()
    X_dif.reverse()

    if len(X_dif) == 1:
        excep == X_dif1
    
    if not X_dif1:
        for N in range(N-1):
            X_dif.pop(0)

if excep == M1:
    print(1)
elif excep == X_dif1:
    print(2)
else:
    print(sum(X_dif))

# print('input >>')
N, M = map(int,(input().split()))
X = list(map(int,(input().split())))
X.sort()
Xdiff = [X[i + 1] - X[i] for i in range(len(X) - 1)]
Xdiff.sort()
ans = sum(Xdiff[:N+1])
if N <= M:
    ans = 0

# print('----------output----------')
print(ans)

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

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

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

N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
X_sub = []
for i in range(len(X)-1):
    X_sub.append(X[i+1]-X[i])
X_sub.sort()
for i in range(N-1):
    del X_sub[-1]
print(X_sub)
print(sum(X_sub))

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

Verdicts: Wrong Answer

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


N,M=map(int,input().split())
X=sorted(list(map(int,input().split())))
if N>=M:
  print(0)
  exit()
else:
  D=[0]*M
  for i in range(M-1):
    D[i]=X[i+1]-X[i]
  print(sum(sorted(D)[:M-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())
l = list(map(int,input().split()))
if M <= N:
    print('0')
else:
    l.sort()
    li = []
    for i in range(M-1):
        difference  = abs(l[i]-l[i+1])
        li.append(difference)
    li.sort().reverse()
    dif = 0
    for i in range(N-1):
        dif += li[i]
    print(l[M-1]-l[0]-dif)

N,M = map(int,input().split())
l = list(map(int,input().split()))
if M <= N:
    print('0')
else:
    l.sort()
    li = []
    for i in range(M-1):
        difference  = abs(l[i]-l[i+1])
        li.append(difference)
    li.sort()
    li.reverse()
    dif = 0
    for i in range(N-1):
        dif += li[i]
    print(l[M-1]-l[0]-dif)

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=list(map(int,input().split()))
L.sort()
if m!=1:

  d=[[L[i+1]-L[i],i] for i in range(m-1)]
  d.sort()
  d.reverse()
  ans=L[m-1]-L[0]

  for i in range(n-1):
    a=d[i][1]
    print(a)
    d[a]=0
    ans-=(L[a+1]-L[a])
  print(ans)
  

else:
  print(0)





import numpy as np
n,m=map(int,input().split())
L=list(map(int,input().split()))
L.sort()

d=np.array([L[i+1]-L[i] for i in range(m-1)])
ans=L[m-1]-L[0]

for i in range(n-1):
  a=argmax(d)
  ans-(L[a+1]-L[a])
  d[a]=0
  




print(ans)


n,m=map(int,input().split())
L=list(map(int,input().split()))
L.sort()
if n>=m:
  print(0)
elif m!=1:

  d=[L[i+1]-L[i] for i in range(m-1)]
  d.sort()
  d.reverse()
  ans=L[-1]-L[0]


  ans-=sum(d[:n-1])
  print(ans)
  

else:
  print(0)



Verdicts: Runtime Error

Runtime Error

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

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

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

x.sort()

print(sum(x[:M-N]))

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

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

x.sort(reverse=True)
print(sum(x[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()))
x.sort()
y=[]
if n>=m:
    print(0)
    exit()
for i in range(m-1):
    y.append(x[i+1]-x[i])
z=sorted(y,reverse=True)
count=0
for i in range(n-1):
    count+=z[i]
print(x)
print(z)
print(x[-1]-x[0]-count)

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

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

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()
cheak = [0]*m
for i in range(m):
    cheak[m] = abs[x[m+1]-x[m]]
cheak.sort()
for j in range(n-1):
    cheak.pop(m-j)
ans = sum(cheak)
print(ans)

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m, *x = map(int, read().split())
x.sort(reverse=True)
memo = [0] * m
for i, (bf, af) in enumerate(zip(x, x[1:])):
    memo[i] = bf - af
memo.sort(reverse=True)
print(sum(memo[n - 1:]))


Verdicts: Runtime Error

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

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


n, m = map(int, input().split())
x = list(map(int, input().split()))
cnt = 0
if n > m:
    print(0)
    exit()
x.sort()
L = []
for i in range(m - 1):
    L.append(x[i + 1] - x[i])
L.sort()
L.reverse()
for i in range(n-1):
    L.pop(0)
print(sum(L))


Verdicts: Wrong Answer

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

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

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

X.sort()

buff = []

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


buff.sort()
buff = buff[::-1]

for i in range(min(N-1, len(buff))):
    print(buff.pop(0))

print(sum(buff))

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

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

X.sort()

buff = []

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


buff.sort()
buff = buff[::-1]

for i in range(min(N-1, len(buff))):
    print(buff.pop(0))

print(sum(buff))

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

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

X.sort()

buff = []

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


buff.sort()
buff = buff[::-1]

for i in range(min(N-1, len(buff))):
    

print(sum(buff))

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

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

X.sort()

buff = []

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


buff.sort()
buff = buff[::-1]

for i in range(min(N-1, len(buff))):
    buff.pop(0)

print(sum(buff))

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

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

Verdicts: Wrong Answer

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

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

if M <= N:
    print(0)
else:
    X.sort()
    dX = np.diff(X)
    dX.sort()
    print(sum(dX[:N+1]))

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

if M <= N:
    print(0)
else:
    X.sort()
    # print("X =", X)
    dX = np.diff(X)
    # print("dX =", dX)
    dX.sort()
    print(sum(dX[: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())
a=list(map(int, input().split()))
a.sort(reverse=True)
print(sum(a[m-1:]))


n,m=map(int, input().split())
a=list(map(int, input().split()))
a.sort(reversed=True)
print(sum(a[m-1:]))


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


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


Verdicts: Wrong Answer

Runtime Error

Runtime Error

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

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

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

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


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

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


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

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


Verdicts: Runtime Error

Runtime Error

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

Submission attempts (in order):
line1 = list(map(lambda x: int(x), input().split()))
N = line1[0]
M = line1[1]
X = list(map(lambda x: int(x), input().split()))

if N >= M or M == 1:
  print(0)
else:
  X.sort(key=lambda x:x, reverse=False)

  diff = []

  for i in range(0, M-1):
    diff.append(X[i + 1] - X[i])

  print(diff)

  for i in range(0, N-1):
    maxIndex = diff.index(max(diff))
    diff.pop(maxIndex)

  print(diff)
  print(sum(diff))


line1 = list(map(lambda x: int(x), input().split()))
N = line1[0]
M = line1[1]
X = list(map(lambda x: int(x), input().split()))

if N >= M or M == 1:
  print(0)
else:
  X.sort(key=lambda x:x, reverse=False)

  diff = list(map(lambda x: x[0]-x[1], zip(X[1:],X[:-1])))
  diff.sort(key=lambda s:s, reverse=False)

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


Verdicts: Wrong Answer

Accepted