Buggy python submission (verdict: Runtime Error):
import numpy as np
n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))

if n >= m:
    print(0)
else:
    xs.sort()
    diffs = [xs[i] - xs[i-1] for i in range(1, m)]
    indxs = list(np.array(diffs).argsort()[::-1][:n-1])
    indxs.sort()
    ans = sum(diffs[0:indxs[0]])
    if indxs[-1]+1 < len(diffs):
        ans += sum(diffs[indxs[-1]+1:])
    for i in range(len(indxs)-1):
        ans += sum(diffs[indxs[i]+1:indxs[i+1]])
    print(ans)


Fixed submission:
import numpy as np
n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))

if n >= m:
    print(0)
else:
    xs.sort()
    diffs = [xs[i] - xs[i-1] for i in range(1, m)]
    if n == 1:
        ans = sum(diffs)
    else:
        indxs = list(np.array(diffs).argsort()[::-1][:n-1])
        indxs.sort()
        ans = sum(diffs[0:indxs[0]])
        if indxs[-1]+1 < len(diffs):
            ans += sum(diffs[indxs[-1]+1:])
        for i in range(len(indxs)-1):
            ans += sum(diffs[indxs[i]+1:indxs[i+1]])
    print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))

if n > m:
    print(0)
else:
    xs.sort()
    diffs = [xs[i] - xs[i-1] for i in range(1, m)]
    indxs = list(np.array(diffs).argsort()[::-1][:n-1])
    indxs.sort()
    ans = sum(diffs[0:indxs[0]])
    if indxs[-1]+1 < len(diffs):
        ans += sum(diffs[indxs[-1]+1:])
    for i in range(len(indxs)-1):
        ans += sum(diffs[indxs[i]+1:indxs[i+1]])
    print(ans)

Fixed submission:
import numpy as np
n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))

if n >= m:
    print(0)
else:
    xs.sort()
    diffs = [xs[i] - xs[i-1] for i in range(1, m)]
    if n == 1:
        ans = sum(diffs)
    else:
        indxs = list(np.array(diffs).argsort()[::-1][:n-1])
        indxs.sort()
        ans = sum(diffs[0:indxs[0]])
        if indxs[-1]+1 < len(diffs):
            ans += sum(diffs[indxs[-1]+1:])
        for i in range(len(indxs)-1):
            ans += sum(diffs[indxs[i]+1:indxs[i+1]])
    print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))

if n > m:
    print(0)
else:
    xs.sort()
    diffs = [xs[i] - xs[i-1] for i in range(1, m)]
    indxs = list(np.array(diffs).argsort()[::-1][:n-1])
    indxs.sort()
    ans = sum(diffs[0:indxs[0]]) + sum(diffs[indxs[-1]+1:])
    for i in range(len(indxs)-1):
        ans += sum(diffs[indxs[i]+1:indxs[i+1]])
    print(ans)

Fixed submission:
import numpy as np
n, m = list(map(int, input().split()))
xs = list(map(int, input().split()))

if n >= m:
    print(0)
else:
    xs.sort()
    diffs = [xs[i] - xs[i-1] for i in range(1, m)]
    if n == 1:
        ans = sum(diffs)
    else:
        indxs = list(np.array(diffs).argsort()[::-1][:n-1])
        indxs.sort()
        ans = sum(diffs[0:indxs[0]])
        if indxs[-1]+1 < len(diffs):
            ans += sum(diffs[indxs[-1]+1:])
        for i in range(len(indxs)-1):
            ans += sum(diffs[indxs[i]+1:indxs[i+1]])
    print(ans)