Buggy python submission (verdict: Runtime Error):
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],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]
    d[a]=0
    ans-=(L[a+1]-L[a])
  print(ans)
  

else:
  print(0)






Fixed submission:
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)

Buggy python submission (verdict: Runtime Error):

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]
    d[a]=0
    ans-=(L[a+1]-L[a])
  print(ans)
  

else:
  print(0)






Fixed submission:
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)

Buggy python submission (verdict: Runtime Error):

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)





Fixed submission:
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)

Buggy python submission (verdict: Runtime Error):

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)])
d=[L[i+1]-L[i] for i in range(m-1)]
ans=L[m-1]-L[0]

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




print(ans)

Fixed submission:
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)

Buggy python submission (verdict: Runtime Error):
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=np.argmax(d)
  d[a]=0
  ans-=(L[a+1]-L[a])
  




print(ans)

Fixed submission:
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)

Buggy python submission (verdict: Runtime Error):
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=np.argmax(d)
  d[a]=0
  ans-=(L[a+1]-L[a])
  




print(ans)


Fixed submission:
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)

Buggy python submission (verdict: Runtime Error):
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)


Fixed submission:
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)