Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
h = []
for _ in range(N):
    h.append(int(input()))
h.sort()
i = 0
ans = []
while N - i >= K:
    temp = h[i:i+K]
    ans.append(temp[-1] - temp[0])
    i += 1
print(min(ans))


Fixed submission:
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline
import numpy as np
N, K = [int(x) for x in input().split()]
h = []
for _ in range(N):
    h.append(int(input()))
h.sort()
i = 0
ans = []
while N - i >= K:
    temp = h[i:i+K]
    ans.append(temp[-1] - temp[0])
    i += 1
print(min(ans))


Fixed submission:
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
2 h = [int(input()) for i in range(N)]
3 h.sort()
4 print(min(h[i+K-1] - h[i] for i in range(N-K+1)))

Fixed submission:
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
h = []
for _ in range(N):
    h.append(int(input()))
h.sort()
a = N - K
i = 0
h_left = h[:a]
h_right = h[K:]
h_middle = h[a:K]
if a != N//2:
    ans = min(h_middle[-1] - h_left[0], h_right[-1] - h_middle[0]) 
    for i in range(len(h_right)-1):
        j = a - i - 1
        ans_ = h_right[i] - h_left[j]
        ans = min(ans, ans_)
    print(ans)
else:
    ans = min(h_middle[-1] - h_left[0], h_right[-1] - h_right[0]) 
    for i in range(len(h_right)-1):
        j = a - i - 1
        ans_ = h_right[i] - h_left[j]
        ans = min(ans, ans_)
    print(ans)
    

Fixed submission:
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
h = []
for _ in range(N):
    h.append(int(input()))
h.sort()
a = N - K
i = 0
h_left = h[:a]
h_right = h[K:]
h_middle = h[a:K]
ans = min(h_middle[-1] - h_left[0], h_right[-1] - h_middle[0]) 
for i in range(len(h_right)-1):
    j = a - i - 1
    ans_ = h_right[i] - h_left[j]
    ans = min(ans, ans_)
print(ans)


Fixed submission:
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
h = []
for _ in range(N):
    h.append(int(input()))
h.sort()
i = 0
ans = 10 ** 9
while N - i >= K:
    temp = h[i:i+K]
    ans = min(ans,temp[-1] - temp[0])
    i += 1
print(ans)

Fixed submission:
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline
import numpy as np
N, K = [int(x) for x in input().split()]
h = []
for _ in range(N):
    h.append(int(input()))
h.sort()
i = 0
ans = 10 ** 9
while N - i >= K:
    temp = h[i:i+K]
    ans = min(ans,temp[-1] - temp[0])
    i += 1
print(ans)


Fixed submission:
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))