Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000)

n, k = map(int, input().split())
h_li = [int(input()) for i in range(n)]
a = max(h_li)-min(h_li)
dp = [[-1]*(a+5)]*100010

def dfs(i, choosed):
    if i == n:
        if len(choosed) != k:
            dif = 10000000010
        else:
            dif = max(choosed) - min(choosed)

    elif len(choosed) >= 2 and dp[len(choosed)][max(choosed)-min(choosed)] != -1:
        dif = dp[len(choosed)][max(choosed)-min(choosed)]
            
    elif len(choosed) == k:
        dif = max(choosed) - min(choosed)
        
    else:
        dif = min(
            dfs(i+1, choosed + [h_li[i]]),
            dfs(i+1, choosed)
        )

    return dif

print(dfs(0, []))

Fixed submission:
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h = sorted(h)
dif = 10**9

for i in range(n-k+1):
    if dif > h[i+k-1] - h[i]:
        dif = h[i+k-1] - h[i]

print(dif)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h_li = [int(input()) for i in range(n)]
a = max(h_li)-min(h_li)
dp = [[-1]*(a+5)]*100010



def dfs(i, choosed):
    if i == n:
        if len(choosed) != k:
            dif = 10000000010
        else:
            dif = max(choosed) - min(choosed)

    elif len(choosed) >= 2 and dp[len(choosed)][max(choosed)-min(choosed)] != -1:
        dif = dp[len(choosed)][max(choosed)-min(choosed)]
            
    elif len(choosed) == k:
        dif = max(choosed) - min(choosed)
    else:
        dif = min(
            dfs(i+1, choosed + [h_li[i]]),
            dfs(i+1, choosed)
        )

    return dif

print(dfs(0, []))

Fixed submission:
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h = sorted(h)
dif = 10**9

for i in range(n-k+1):
    if dif > h[i+k-1] - h[i]:
        dif = h[i+k-1] - h[i]

print(dif)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h_li = [int(input()) for i in range(n)]
dp = [[-1]*1000000010]*100010

def dfs(i, choosed):
    if i == n:
        if len(choosed) != k:
            dif = 10000000010
        else:
            dif = max(choosed) - min(choosed)

    elif len(choosed) >= 2 and dp[len(choosed)][max(choosed)-min(choosed)] != -1:
        dif = dp[len(choosed)][max(choosed)-min(choosed)]
            
    elif len(choosed) == k:
        dif = max(choosed) - min(choosed)
    else:
        dif = min(
            dfs(i+1, choosed + [h_li[i]]),
            dfs(i+1, choosed)
        )

    return dif

print(dfs(0, []))

Fixed submission:
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h = sorted(h)
dif = 10**9

for i in range(n-k+1):
    if dif > h[i+k-1] - h[i]:
        dif = h[i+k-1] - h[i]

print(dif)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h_li = [int(input()) for i in range(n)]

def dfs(i, choosed):
    if i == n:
        if len(choosed) != k:
            dif = 10000000000
        else:
            dif = max(choosed) - min(choosed)
            
    elif len(choosed) == k:
        dif = max(choosed) - min(choosed)
    else:
        dif = min(
            dfs(i+1, choosed + [h_li[i]]),
            dfs(i+1, choosed)
        )

    return dif

print(dfs(0, []))

Fixed submission:
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h = sorted(h)
dif = 10**9

for i in range(n-k+1):
    if dif > h[i+k-1] - h[i]:
        dif = h[i+k-1] - h[i]

print(dif)