Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = []
for i in range(n):
  h.append(int(input()))
h.sort()
g = float('inf')
for i in range(n-k+1):
  g = min(g, h[i:i+k][-1] - h[i:i+k][0])
print(g)

Fixed submission:
n,k = map(int,input().split())
h = []
for i in range(n):
  h.append(int(input()))
h.sort()
g = float('inf')
for i in range(n-k+1):
  g = min(g, h[i+k-1] - h[i])
print(g)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = []
for i in range(n):
  h.append(int(input()))
h.sort()
g = float('inf')
for i in range(n-k+1):
  g = min(g, max(h[i:i+k]) - min(h[i:i+k]))
print(g)

Fixed submission:
n,k = map(int,input().split())
h = []
for i in range(n):
  h.append(int(input()))
h.sort()
g = float('inf')
for i in range(n-k+1):
  g = min(g, h[i+k-1] - h[i])
print(g)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = []
for i in range(n):
  h.append(int(input()))
h.sort()
g = float('inf')
for i in range(n-k+1):
  if g > max(h[i:i+k]) - min(h[i:i+k]):
    g = max(h[i:i+k]) - min(h[i:i+k])
print(g)

Fixed submission:
n,k = map(int,input().split())
h = []
for i in range(n):
  h.append(int(input()))
h.sort()
g = float('inf')
for i in range(n-k+1):
  g = min(g, h[i+k-1] - h[i])
print(g)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = []
for i in range(n):
  h.append(int(input()))
h.sort()
g = []
for i in range(n-k+1):
  g.append(max(h[i:i+k]) - min(h[i:i+k]))
print(min(g))

Fixed submission:
n,k = map(int,input().split())
h = []
for i in range(n):
  h.append(int(input()))
h.sort()
g = float('inf')
for i in range(n-k+1):
  g = min(g, h[i+k-1] - h[i])
print(g)

Buggy python submission (verdict: Runtime Error):
NK = [int(i) for i in input().split()]
N,K = NK[0],NK[1]
h = []
h1 = []
for i in range(N):
    h.append(int(input()))
h.sort()
for i in range(N-1):
    h1.append(h[i+1]-h[i])
hh,hhh = [],[]
for i in range(N-K):
    hh.append([0]*i+h1+[0]*(K-2-i))
for i in range(N-K+1):
    h2 = 0
    for j in range(K-1):
        h2 = h2 + hh[j][i+K-2]
    hhh.append(h2)
print(min(hhh))
    

Fixed submission:
n,k = map(int,input().split())
h = []
for i in range(n):
  h.append(int(input()))
h.sort()
g = float('inf')
for i in range(n-k+1):
  g = min(g, h[i+k-1] - h[i])
print(g)

Buggy python submission (verdict: Runtime Error):
NK = [int(i) for i in input().split()]
N,K = NK[0],NK[1]
h = []
h1 = []
for i in range(N):
    h.append(int(input()))
h.sort()
for i in range(N-1):
    h1.append(h[i+1]-h[i])
hh,hhh = [],[]
for i in range(N-K):
    hh.append([0]*i+h1+[0]*(K-2-i))
for i in range(N-K+1):
    h2 = 0
    for j in range(K-1):
        h2 = h2 + hh[j][i+K-2]
        hhh.append(h2)
print(min(hhh))
    

Fixed submission:
n,k = map(int,input().split())
h = []
for i in range(n):
  h.append(int(input()))
h.sort()
g = float('inf')
for i in range(n-k+1):
  g = min(g, h[i+k-1] - h[i])
print(g)

Buggy python submission (verdict: Runtime Error):
NK = [int(i) for i in input().split()]
N,K = NK[0],NK[1]
h = []
h1 = []
for i in range(N):
  h.append(int(input()))
h.sort()
for i in range(N-1):
  h1.append(h[i+1]-h[i])
hh,hhh = [],[]
for i in range(N-K):
  hh.append([0]*i+h1+[0]*(K-2-i))
for i in range(N-K+1):
  h2 = 0
  for j in range(K-1):
      h2 = h2 + hh[j][i+K-2]
  hhh.append(h2)
print(min(hhh))
    

Fixed submission:
n,k = map(int,input().split())
h = []
for i in range(n):
  h.append(int(input()))
h.sort()
g = float('inf')
for i in range(n-k+1):
  g = min(g, h[i+k-1] - h[i])
print(g)

Buggy python submission (verdict: Runtime Error):
NK = [int(i) for i in input().split()]
N,K = NK[0],NK[1]
h = []
h1 = []
for i in range(N):
    h.append(int(input()))
h.sort()
for i in range(N-1):
    h1.append(h[i+1]-h[i])
hh,hhh = [],[]
for i in range(N-K):
    hh.append([0]*i+h1+[0]*(K-2-i))
for i in range(N-K+1):
    h2 = 0
    for j in range(K-1):
        h2 = h2 + hh[j][i+K-2]
    hhh.append(h2)
print(min(hhh))
    

Fixed submission:
n,k = map(int,input().split())
h = []
for i in range(n):
  h.append(int(input()))
h.sort()
g = float('inf')
for i in range(n-k+1):
  g = min(g, h[i+k-1] - h[i])
print(g)