Problem p03137 (python)

Fixed submission:
N,M = list(map(int,input().split()))
xarray = sorted(list(map(int,input().split())))
 
diff = []
if len(xarray) == 1:
    print(0)
elif N >= M:
    print(0)
else:
    for i in range(len(xarray)-1):
        diff.append(abs(xarray[i+1]-xarray[i]))
 
    if len(diff) == 0:
        print(0)
    else:
        diff2 = sorted(diff, reverse = True)
        
 
        if N == 1:
            
            print(sum(diff2))
        else:
            for j in range(N-1):
                diff2[j] = 0
            
            print(sum(diff2))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
X = sorted(list(map(int,input().split())))
diff = []
for i in range(M-1):
    diff.append(X[i+1] - X[i])
diff.sort(reverse = True)
for i in range(N-1):
    diff.pop(0)
print(sum(diff))

Buggy submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
xarray = sorted(list(map(int,input().split())))
 
diff = []
if len(xarray) == 1:
    print(0)
elif N == M:
    print(0)
else:
    for i in range(len(xarray)-1):
        diff.append(abs(xarray[i+1]-xarray[i]))
 
    if len(diff) == 0:
        print(0)
    else:
        diff2 = sorted(diff, reverse = True)
        
 
        if N == 1:
            
            print(sum(diff2))
        else:
            for j in range(N-1):
                diff2[j] = 0
            
            print(sum(diff2))

Buggy submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
xarray = list(map(int,input().split()))
xarray.sort()

diff = []
if len(xarray) == 1:
    print(0)
elif N == M:
    print(0)
else:
    for i in range(len(xarray)-1):
        diff.append(abs(xarray[i+1]-xarray[i]))

    if len(diff) == 0:
        print(0)
    else:
        diff2 = sorted(diff, reverse = True)
        

        if N == 1:
            
            print(sum(diff2))
        else:
            for j in range(N-1):
                diff2[j] = 0
            
            print(sum(diff2))

Buggy submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
xarray = list(map(int,input().split()))
xarray.sort()
print(xarray)
diff = []
if len(xarray) == 1:
    print(0)
else:
    for i in range(len(xarray)-1):
        diff.append(abs(xarray[i+1]-xarray[i]))
    if len(diff) == 0:
        print(0)
    else:
        diff2 = sorted(diff, reverse = True)
        print(diff)
        print(diff2)

        if N == 1:
            
            print(sum(diff2))
        else:
            for j in range(N-1):
                diff2[j] = 0
            print(sum(diff2))

Buggy submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
xarray = list(map(int,input().split()))
xarray.sort()
diff = []
if len(xarray) == 1:
    print(0)
else:
    for i in range(len(xarray)-1):
        diff.append(abs(xarray[i+1]-xarray[i]))
    if len(diff) == 0:
        print(0)
    else:
        diff2 = sorted(diff, reverse = True)

        if N == 1:
            diff2[0] = 0
            print(sum(diff2))
        else:
            for j in range(N-1):
                diff2[j] = 0
            print(sum(diff2))

Buggy submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
xarray = list(map(int,input().split()))
diff = []
if len(xarray) == 1:
    print(0)
else:
    for i in range(len(xarray)-1):
        diff.append(abs(xarray[i+1]-xarray[i]))
    if len(diff) == 0:
        print(0)
    else:
        diff2 = sorted(diff, reverse = True)
        for j in range(N):
            diff2[j] = 0
        print(sum(diff2))

Buggy submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
xarray = list(map(int,input().split()))
diff = []
for i in range(len(xarray)-1):
    diff.append(abs(xarray[i+1]-xarray[i]))

if len(diff) == 0:
    print(0)
else:
    diff2 = sorted(diff, reverse = True)
    for j in range(N):
        diff2[j] = 0
    print(sum(diff2))

Buggy submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
xarray = list(map(int,input().split()))
diff = []
for i in range(len(xarray)-1):
    diff.append(abs(xarray[i+1]-xarray[i]))
diff2 = sorted(diff, reverse = True)
if len(diff2) == 0:
    print(0)
else:
    for j in range(N):
        diff2[j] = 0
    print(sum(diff2))

Buggy submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
xarray = list(map(int,input().split()))
diff = []
for i in range(len(xarray)-1):
    diff.append(abs(xarray[i+1]-xarray[i]))
diff2 = sorted(diff, reverse = True)
for j in range(N):
    diff2[j] = 0
print(sum(diff2))