Buggy python submission (verdict: Runtime Error):
import numpy as np
 
N,M=[int(i) for i in input().split()]
x=input().split()
y=[int(i) for i in x]
y.sort()
if(N==1):
    print(max(y)-min(y))
#    print(y[M-1]-y[0])
    exit()
if(M==1):
    print("0")
    exit()
diff=[]
for i in range(M-1):
    diff.append(y[i+1]-y[i])
sub=[]
array=np.array(diff)
index=np.argsort(array)
c=index[-1::-1]
for i in range(N-1):
    sub.append(c[i])
ans=0
for i in range(N):
    if(i==0):
        ans+=y[sub[i]]-y[0]
    elif(i==N-1):
        ans+=y[M-1]-y[sub[i-1]+1]
    else:
        ans+=y[sub[i]]-y[sub[i-1]+1]
print(ans)

Fixed submission:
import numpy as np
 
N,M=[int(i) for i in input().split()]
x=input().split()
y=[int(i) for i in x]
y.sort()
if(N==1):
    print(max(y)-min(y))
#    print(y[M-1]-y[0])
    exit()
if(M==1):
    print("0")
    exit()
if(N>=M):
    print("0")
    exit()
diff=[]
for i in range(M-1):
    diff.append(y[i+1]-y[i])
sub=[]
array=np.array(diff)
index=np.argsort(array)
c=index[-1::-1]
for i in range(N-1):
    sub.append(c[i])
ans=0
for i in range(N):
    if(i==0):
        ans+=y[sub[i]]-y[0]
    elif(i==N-1):
        ans+=y[M-1]-y[sub[i-1]+1]
    else:
        ans+=y[sub[i]]-y[sub[i-1]+1]
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N,M=[int(i) for i in input().split()]
x=input().split()
y=[int(i) for i in x]
y.sort()

if(N==1):
    print(y[M-1]-y[0])
    exit()
if(M==1):
    print("0")
    exit()

diff=[]
for i in range(M-1):
    diff.append(y[i+1]-y[i])
sub=[]
array=np.array(diff)
index=np.argsort(array)
c=index[-1::-1]
for i in range(N-1):
    sub.append(c[i])
print(sub)
ans=0
for i in range(N):
    if(i==0):
        ans+=y[sub[i]]-y[0]
    elif(i==N-1):
        ans+=y[M-1]-y[sub[i-1]+1]
    else:
        ans+=y[sub[i]]-y[sub[i-1]+1]
print(ans)

Fixed submission:
import numpy as np
 
N,M=[int(i) for i in input().split()]
x=input().split()
y=[int(i) for i in x]
y.sort()
if(N==1):
    print(max(y)-min(y))
#    print(y[M-1]-y[0])
    exit()
if(M==1):
    print("0")
    exit()
if(N>=M):
    print("0")
    exit()
diff=[]
for i in range(M-1):
    diff.append(y[i+1]-y[i])
sub=[]
array=np.array(diff)
index=np.argsort(array)
c=index[-1::-1]
for i in range(N-1):
    sub.append(c[i])
ans=0
for i in range(N):
    if(i==0):
        ans+=y[sub[i]]-y[0]
    elif(i==N-1):
        ans+=y[M-1]-y[sub[i-1]+1]
    else:
        ans+=y[sub[i]]-y[sub[i-1]+1]
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N,M=[int(i) for i in input().split()]
x=input().split()
y=[int(i) for i in x]
y.sort()
if(M==1):
    print("0")
    exit()
if(N==1):
    print(y[M-1]-y[0])
    exit()

diff=[]
for i in range(M-1):
    diff.append(y[i+1]-y[i])
sub=[]
array=np.array(diff)
index=np.argsort(array)
c=index[-1::-1]
for i in range(N-1):
    sub.append(c[i])
print(sub)
ans=0
for i in range(N):
    if(i==0):
        ans+=y[sub[i]]-y[0]
    elif(i==N-1):
        ans+=y[M-1]-y[sub[i-1]+1]
    else:
        ans+=y[sub[i]]-y[sub[i-1]+1]
print(ans)

Fixed submission:
import numpy as np
 
N,M=[int(i) for i in input().split()]
x=input().split()
y=[int(i) for i in x]
y.sort()
if(N==1):
    print(max(y)-min(y))
#    print(y[M-1]-y[0])
    exit()
if(M==1):
    print("0")
    exit()
if(N>=M):
    print("0")
    exit()
diff=[]
for i in range(M-1):
    diff.append(y[i+1]-y[i])
sub=[]
array=np.array(diff)
index=np.argsort(array)
c=index[-1::-1]
for i in range(N-1):
    sub.append(c[i])
ans=0
for i in range(N):
    if(i==0):
        ans+=y[sub[i]]-y[0]
    elif(i==N-1):
        ans+=y[M-1]-y[sub[i-1]+1]
    else:
        ans+=y[sub[i]]-y[sub[i-1]+1]
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N,M=[int(i) for i in input().split()]
x=input().split()
y=[int(i) for i in x]
y.sort()
if(N==1):
    print(y[M-1]-y[0])
    exit()
if(M==1):
    print("0")
    exit()
diff=[]
for i in range(M-1):
    diff.append(y[i+1]-y[i])
sub=[]
array=np.array(diff)
index=np.argsort(array)
c=index[-1::-1]
for i in range(N-1):
    sub.append(c[i])
ans=0
for i in range(N):
    if(i==0):
        ans+=y[sub[i]]-y[0]
    elif(i==N-1):
        ans+=y[M-1]-y[sub[i-1]+1]
    else:
        ans+=y[sub[i]]-y[sub[i-1]+1]
print(ans)


Fixed submission:
import numpy as np
 
N,M=[int(i) for i in input().split()]
x=input().split()
y=[int(i) for i in x]
y.sort()
if(N==1):
    print(max(y)-min(y))
#    print(y[M-1]-y[0])
    exit()
if(M==1):
    print("0")
    exit()
if(N>=M):
    print("0")
    exit()
diff=[]
for i in range(M-1):
    diff.append(y[i+1]-y[i])
sub=[]
array=np.array(diff)
index=np.argsort(array)
c=index[-1::-1]
for i in range(N-1):
    sub.append(c[i])
ans=0
for i in range(N):
    if(i==0):
        ans+=y[sub[i]]-y[0]
    elif(i==N-1):
        ans+=y[M-1]-y[sub[i-1]+1]
    else:
        ans+=y[sub[i]]-y[sub[i-1]+1]
print(ans)