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

Submission attempts (in order):
# - coding : utf-8 -*-
 
n, m = input().split()
xs_str = input().split()
xs = list(map(int, xs_str))
xs.sort()
 
ys = []
for x1, x2 in zip(xs[0:-1], xs[1:]):
    ys.append(abs(x2 - x1))
ys.sort()
 
if len(ys) > n:
    out = sum(ys[0:-(n-1)])
else:
    out = 0
print(out)

# - coding : utf-8 -*-
 
n, m = input().split()
xs_str = input().split()
xs = [int(i) for i in input().split()]
xs.sort()
 
ys = []
for x1, x2 in zip(xs[0:-1], xs[1:]):
    ys.append(abs(x2 - x1))
ys.sort()
 
out = sum(ys[0:-(int(n)-1)])
print(out)

# - coding : utf-8 -*-
 
n, m = input().split()
xs_str = input().split()
xs = list(map(int, xs_str))
xs.sort()
 
ys = []
for x1, x2 in zip(xs[0:-1], xs[1:]):
    ys.append(abs(x2 - x1))
ys.sort()
 
if len(ys) >= n:
    out = sum(ys[0:-(n-1)])
else:
    out = 0
print(out)


# - coding : utf-8 -*-
 
n, m = input().split()
xs_str = input().split()
xs = list(map(int, xs_str))
xs.sort()
 
ys = []
for i in range(int(m) - 1):
    ys.append(abs(xs[i+1] - xs[i])
ys.sort()
 
out = sum(ys[0:-(int(n)-1)])
print(out)

# - coding : utf-8 -*-
 
n, m = input().split()
xs_str = input().split()
xs = list(map(int, xs_str))
sortted(xs)
 
ys = []
for i in range(int(m) - 1):
    ys.append(abs(xs[i+1] - xs[i]))
sorted(ys)
 
out = sum(ys[0:-(int(n)-1)])
print(out)

# - coding : utf-8 -*-
 
n, m = map(int, input().split())
xs = list(map(int, input().split()))
sorted(xs)
 
ys = []
for i in range(m - 1):
    ys.append(xs[i+1] - xs[i])
sorted(ys)

out = sum(ys[0:-(n-1)])
print(out)

# - coding : utf-8 -*-
 
n, m = map(int, input().split())
xs = list(map(int, input().split()))
sorted(xs)
 
ys = []
for i in range(m - 1):
    ys.append(xs[i+1] - xs[i])
sorted(ys)

if len(ys) >= n:
    out = sum(ys[0:-(n-1)])
else:
    out = 0
print(out)

# - coding : utf-8 -*-
 
n, m = input().split()
xs_str = input().split()
xs = list(map(int, xs_str))
sorted(xs)
 
ys = []
for i in range(int(m) - 1):
    ys.append(abs(xs[i+1] - xs[i]))
sorted(ys)
 
out = sum(ys[0:-(int(n)-1)])
print(out)

# - coding : utf-8 -*-
 
n, m = input().split()
xs_str = input().split()
xs = list(map(int, xs_str))
sorted(xs)
 
ys = []
for i in range(int(m) - 1):
    ys.append(xs[i+1] - xs[i])
sorted(ys)

out = sum(ys[0:-(int(n)-1)])
print(out)

# - coding : utf-8 -*-
 
n, m = list(map(int, input().split()))
xs_str = input().split()
xs = list(map(int, xs_str))
xs.sort()
 
ys = []
for x1, x2 in zip(xs[0:-1], xs[1:]):
    ys.append(abs(x2 - x1))
ys.sort()

for i in range(n - 1):
    if ys == []:
        break
    else:
        ys.pop()
print(sum(ys))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted