Problem: p03137
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
dif=[]
if m<=n:
  print(0)
  sys.exit()
else:
  for i in range(m-1):
    dif.append(x[i+1]-x[i]-1)
  dif.sort(reverse=True)
  ans=x[m-1]-x[0]+1
  for j in range(n-1):
    ans-=dif[j]
  print(ans-n+1)
  


Failing test case input:
4 7
-23 -1 1 7 -140 1 0

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import sys
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
dif=[]
if m<=n:
  print(0)
  sys.exit()
else:
  for i in range(m-1):
    dif.append(x[i+1]-x[i])
  dif.sort(reverse=True)
  ans=x[m-1]-x[0]
  for j in range(n-1):
    ans-=dif[j]
  print(ans)

Problem: p03137
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,m=map(int,input().split())
x=[int(i) for i in input().split()]
x.sort()
d=[]
for i in range(m-1):
    d.append(x[i+1]-x[i])
d.sort()
print(sum(d[:-n+1]))

Failing test case input:
1 7
-8 -1 0 9 -100 2 17

Expected output:
117


Actual output:
0


Fixed submission (verdict: Accepted):
import sys
n,m=map(int,input().split())
x=[int(i) for i in input().split()]
x.sort()
d=[]
for i in range(m-1):
    d.append(x[i+1]-x[i])
d.sort()
if n==1:
    print(sum(d))
else:
    print(sum(d[:-n+1]))

Problem: p03137
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = [int(_) for _ in input().split()]
X = sorted([int(_) for _ in input().split()])
D = sorted([X[i + 1] - X[i] for i in range(M - 1)])
print(X[-1] - X[0] - sum(D[-N + 1:]))

Failing test case input:
1 7
-8 -1 0 9 -100 2 17

Expected output:
117


Actual output:
0


Fixed submission (verdict: Accepted):
N, M = [int(_) for _ in input().split()]
X = sorted([int(_) for _ in input().split()])
D = sorted([X[i + 1] - X[i] for i in range(M - 1)])
print(X[-1] - X[0] - sum(D[max(M - N,0):]))

Problem: p03137
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int, input().split())
if N > M:
    print(0)
    exit()
X = list(map(int, input().split()))
X.sort()
leng = []
for i in range(1, M):
    leng.append(X[i] - X[i-1])
leng.sort()
print(sum(leng[:M-3]))

Failing test case input:
2 7
-28 -3 0 9 -5 0 7

Expected output:
14


Actual output:
7


Fixed submission (verdict: Accepted):
N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >= M:
    print(0)
    exit()
X.sort()
leng = []
for i in range(1, M):
    leng.append(X[i] - X[i-1])
ans = sorted(leng, reverse = True)
print(sum(ans[N - 1:]))

Problem: p03137
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, M = map(int,input().split())
X = sorted(list(map(int,input().split())))

tmp = sorted([X[i+1] - X[i] for i in range(M-1)])
if(tmp != []):
  print(sum(tmp[:-(N-1)]))
else:
  print(0)

Failing test case input:
1 7
-8 -1 0 9 -100 2 17

Expected output:
117


Actual output:
0


Fixed submission (verdict: Accepted):
N, M = map(int,input().split())
X = sorted(list(map(int,input().split())))

tmp = sorted([X[i+1] - X[i] for i in range(M-1)])
if(tmp != []):
  if(len(tmp) == 1):
    print(*tmp)
  elif(N == 1):
    print(sum(tmp))
  else:
    print(sum(tmp[:-(N-1)]))
else:
  print(0)