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

n, m = map(int, input().split())

l = [int(i) for i in input().split()]
l.sort()
if n == 1 or m == 1 or m == 2:
    print(l[-1]-l[0])
else:
    d = [0 for i in range(m - 1)]
    for i in range(m-1):
        d[i] = l[i+1] - l[i]
    d = np.array(d)
    dl = d.argsort()[::-1]
    count = 0
    for i in range(n):
        if i == 0:
            count += l[dl[i]] - l[0]
            index = dl[i]
        elif i == n - 1:
            count += l[-1] - l[index+1]
        else:
            count += l[dl[i]] - l[index+1]
            index = dl[i]
    print(count)


Fixed submission:
import numpy as np

n, m = map(int, input().split())

l = [int(i) for i in input().split()]
l.sort()
if n == 1 or m == 1:
    print(l[-1]-l[0])
elif n > m:
    print(0)
else:
    d = [0 for i in range(m - 1)]
    for i in range(m-1):
        d[i] = l[i+1] - l[i]
    d = np.array(d)
    dl = d.argsort()[::-1]
    count = 0
    for i in range(n):
        if i == 0:
            count += l[dl[i]] - l[0]
            index = dl[i]
        elif i == n - 1:
            count += l[-1] - l[index+1]
        else:
            count += l[dl[i]] - l[index+1]
            index = dl[i]
    print(count)

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

n, m = map(int, input().split())

l = [int(i) for i in input().split()]
l.sort()
if n == 1 or m == 1:
    print(l[-1]-l[0])
else:
    d = [0 for i in range(m - 1)]
    for i in range(m-1):
        d[i] = l[i+1] - l[i]
    d = np.array(d)
    dl = d.argsort()[::-1]
    count = 0
    for i in range(n):
        if i == 0:
            count += l[dl[i]] - l[0]
            index = dl[i]
        elif i == n - 1:
            count += l[-1] - l[index+1]
        else:
            count += l[dl[i]] - l[index+1]
            index = dl[i]
    print(count)


Fixed submission:
import numpy as np

n, m = map(int, input().split())

l = [int(i) for i in input().split()]
l.sort()
if n == 1 or m == 1:
    print(l[-1]-l[0])
elif n > m:
    print(0)
else:
    d = [0 for i in range(m - 1)]
    for i in range(m-1):
        d[i] = l[i+1] - l[i]
    d = np.array(d)
    dl = d.argsort()[::-1]
    count = 0
    for i in range(n):
        if i == 0:
            count += l[dl[i]] - l[0]
            index = dl[i]
        elif i == n - 1:
            count += l[-1] - l[index+1]
        else:
            count += l[dl[i]] - l[index+1]
            index = dl[i]
    print(count)

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

n, m = map(int, input().split())

l = [int(i) for i in input().split()]
l.sort()
d = [0 for i in range(m - 1)]
for i in range(m-1):
    d[i] = l[i+1] - l[i]
d = np.array(d)
dl = d.argsort()[::-1]
count = 0
if n == 1 or m == 1:
    print(l[-1]-l[0])
else:
    for i in range(n):
        if i == 0:
            count += l[dl[i]] - l[0]
            index = dl[i]
        elif i == n - 1:
            count += l[-1] - l[index+1]
        else:
            count += l[dl[i]] - l[index+1]
            index = dl[i]
print(count)


Fixed submission:
import numpy as np

n, m = map(int, input().split())

l = [int(i) for i in input().split()]
l.sort()
if n == 1 or m == 1:
    print(l[-1]-l[0])
elif n > m:
    print(0)
else:
    d = [0 for i in range(m - 1)]
    for i in range(m-1):
        d[i] = l[i+1] - l[i]
    d = np.array(d)
    dl = d.argsort()[::-1]
    count = 0
    for i in range(n):
        if i == 0:
            count += l[dl[i]] - l[0]
            index = dl[i]
        elif i == n - 1:
            count += l[-1] - l[index+1]
        else:
            count += l[dl[i]] - l[index+1]
            index = dl[i]
    print(count)