ZhenlongDai/ACPR huggingface dataset:
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = input().split()
n=int(n)
k=int(k)
h = [int(input()) for i in range(n)]
h.sort()

ans=10000000000

for i in range(n-k+1):
  list1 = [h[j] for j in range(i,i+k)]
  print(list1)
  if max(list1)-min(list1) < ans:
      ans = max(list1)-min(list1)
print(ans)

Failing test case input:
5 2
8
8
17
0
11

Expected output:
0


Actual output:
[0, 8]
[8, 8]
[8, 11]
[11, 17]
0


Fixed submission (verdict: Accepted):
n,k = input().split()
n=int(n)
k=int(k)
h = [int(input()) for i in range(n)]
h.sort()

ans=10000000000

for i in range(n-k+1):


  if h[i+k-1]-h[i] < ans:
      ans = h[i+k-1]-h[i]
print(ans)

Problem: p03208
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k=map(int,input().split())
H=[]
for i in range(n):
    H.append(int(input()))
H.sort()

Hd=[]
for i in range(1,n):
    Hd.append(H[i]-H[i-1])
Hd.sort()
ans = sum(Hd[:k-1])
print(ans)

Failing test case input:
5 3
5
2
2
0
6

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
H=[]
for i in range(n):
    H.append(int(input()))
H.sort()
ans = min( H[i+k-1]-H[i] for i in range( n-k+1 ) )
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = []
[h.append(int(input())) for i in range(N)]

h.sort()
print(h)
l = []
for i in range(N-K+1):
    l.append(h[i+K-1] - h[i])
print(min(l))

Failing test case input:
4 3
10
21
11
1
6

Expected output:
10


Actual output:
[1, 10, 11, 21]
10


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = []
[h.append(int(input())) for i in range(N)]

h.sort()
l = []
for i in range(N-K+1):
    l.append(h[i+K-1] - h[i])
print(min(l))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = list(map(int, input().split()))
h = [int(input()) for i in range(N)]
candidate = None
h.sort()
for i in range(N-K-1):
    tmp = h[i+K-1] - h[i]
    if candidate == None or tmp < candidate:
        candidate = tmp
print(candidate)

Failing test case input:
5 3
5
7
5
1
5

Expected output:
0


Actual output:
4


Fixed submission (verdict: Accepted):
N,K = list(map(int, input().split()))
h = [int(input()) for i in range(N)]
candidate = None
h.sort()
for i in range(N-K+1):
    tmp = h[i+K-1] - h[i]
    if candidate == None or tmp < candidate:
        candidate = tmp
print(candidate)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h_list = []

for _ in range(N):
    h_list.append(int(input()))

h_list.sort()
answer = h_list[N-1] - h_list[0]

for i in range(N-K+1):
    a = h_list[i+K-2] - h_list[i]
    answer = min(a,answer)

print(answer)

Failing test case input:
5 3
5
7
10
0
13

Expected output:
5


Actual output:
2


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h_list = []

for _ in range(N):
    h_list.append(int(input()))

h_list.sort()
answer = h_list[N-1] - h_list[0]

for i in range(N-K+1):
    a = h_list[i+K-1] - h_list[i]
    answer = min(a,answer)

print(answer)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 1000000000
for i in range(K):
    if(K+i == N):
        break
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Failing test case input:
4 3
10
21
21
-2
10

Expected output:
11


Actual output:
23


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 10000000000
loop = N-K+1
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K=(int(i) for i in input().split())
h=[]
for i in range(N):
    h.append(int(input()))

h.sort()
m=abs(h[0]-h[K-1])
for i in range(1,N-K):
    if m>abs(h[i]-h[K-1]):
        m=abs(h[i]-h[K-1])
print(m)

Failing test case input:
5 4
10
21
28
0
8

Expected output:
20


Actual output:
21


Fixed submission (verdict: Accepted):
N,K=(int(i) for i in input().split())
h=[]
for i in range(N):
    h.append(int(input()))

h.sort()
m=abs(h[0]-h[K-1])
for i in range(1,N-K+1):
    if m>abs(h[i]-h[i+K-1]):
        m=abs(h[i]-h[i+K-1])
print(m)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
H = sorted([int(i) for i in range(N)])

ans = float("inf")
for i in range(N-K+1):
    ans = min(ans, H[i+K-1]-H[i])

print(ans)

Failing test case input:
5 2
8
8
10
0
11

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
H = sorted([int(input()) for i in range(N)])

ans = float("inf")
for i in range(N-K+1):
    ans = min(ans, H[i+K-1]-H[i])

print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
ps = []
for i in range(N):
	ps.append(int(input()))
ps = sorted(ps)
ans = ps[K-1]-ps[0]
for i in range(N - K):
	ans = min(ans, ps[i+K-1], ps[i])
print(ans)


Failing test case input:
5 3
10
25
19
0
6

Expected output:
10


Actual output:
0


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
ps = []
for i in range(N):
	ps.append(int(input()))
ps = sorted(ps)
ans = ps[K-1]-ps[0]
for i in range(N-K+1):
	ans = min(ans, ps[i+K-1]-ps[i])
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
h=[int(input())for i in range(n)]
h.sort()
ans=1000000000
for i in range(k,n):
  ans=min(ans,h[i]-h[i-k])
print(ans)

Failing test case input:
5 1
3
2
16
0
11

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
h=[int(input())for i in range(n)]
h.sort()
ans=1000000000
for i in range(k-1,n):
  ans=min(ans,h[i]-h[i-k+1])
print(ans)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N,K = read_int()
h = [read_int()[0] for _ in range(N)]
h.sort()

def solve():
    ans = float('INF')
    for i in range(N - K):
        ans = min(ans, h[i + K - 1] - h[i])
    return ans

if __name__ == "__main__":
    print(solve())


Failing test case input:
4 3
18
21
21
0
10

Expected output:
3


Actual output:
21


Fixed submission (verdict: Accepted):
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N,K = read_int()
h = [read_int()[0] for _ in range(N)]
h.sort()

def solve():
    ans = float('INF')
    for i in range(N - K + 1):
        ans = min(ans, h[i + K - 1] - h[i])
    return ans

if __name__ == "__main__":
    print(solve())

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
h = [0]*n
for i in range(n):
    h[i] = int(input())
c = 10**9
h.sort()
for j in range(n-k):
    c =  min(c,h[j+k-1]-h[j])
print(c)

Failing test case input:
3 3
5
7
5
1
5

Expected output:
2


Actual output:
1000000000


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
h = [0]*n
for i in range(n):
    h[i] = int(input())
c = 10**9
h.sort()
for j in range(n-k+1):
    c =  min(c,h[j+k-1]-h[j])
print(c)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n,k = (int(i) for i in input().split())
t = [int(input()) for i in range(n)] 

t = sorted(t)
min = t[k-1]-t[0]
for i in range(n-k):
    s = t[i+k-1]-t[i]
    if s < min:
        min = s

print(min)

    

Failing test case input:
4 3
10
21
21
-1
6

Expected output:
11


Actual output:
22


Fixed submission (verdict: Accepted):

n,k = (int(i) for i in input().split())
t = [int(input()) for i in range(n)] 

t = sorted(t)
min = t[k-1]-t[0]
for i in range(n-k+1):
    s = t[i+k-1]-t[i]
    if s < min:
        min = s

print(min)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
h=sorted([int(input()) for _ in range(n)])
gap=[h[i]-h[i-1] for i in range(1,n)]
tmp=0
lst=[gap[0]]
for i in range(1,len(gap)):
    lst.append(gap[i]+lst[i-1])
print(gap,lst)
ans=[lst[k-2]]
for i in range(k,n):
    ans.append(lst[i-1]-lst[i-k])
print(ans)
print(min(ans))

Failing test case input:
3 3
5
7
10
7
0

Expected output:
5


Actual output:
[2, 3] [2, 5]
[5]
5


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
h=sorted([int(input()) for _ in range(n)])
gap=[h[i]-h[i-1] for i in range(1,n)]
tmp=0
lst=[gap[0]]
for i in range(1,len(gap)):
    lst.append(gap[i]+lst[i-1])

ans=[lst[k-2]]
for i in range(k,n):
    ans.append(lst[i-1]-lst[i-k])

print(min(ans))
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
L=sorted([int(input()) for _ in range(n)])
ans=0
for i in range(n-k):
    ans=min(L[i+k-1]-L[i],ans)
print(ans)

Failing test case input:
3 3
4
7
5
1
5

Expected output:
3


Actual output:
0


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
L=sorted([int(input()) for _ in range(n)])
ans=10**10
for i in range(n-k+1):
    ans=min(L[i+k-1]-L[i],ans)
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
h = sorted([int(input()) for _ in range(n)])
print(h)
ans = []
for i in range(n-k+1):
  ans.append(h[i+k-1]-h[i])
print(min(ans))

Failing test case input:
4 4
1
38
1
0
8

Expected output:
38


Actual output:
[0, 1, 1, 38]
38


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
h = sorted([int(input()) for _ in range(n)])
ans = []
for i in range(n-k+1):
  ans.append(h[i+k-1]-h[i])
print(min(ans))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = []
min_d = 10 ** 10

h = [int(input()) for i in range(N)]
h = sorted(h)

for i in range(N-2) : 
    tmp = [h[i], h[i+1], h[i+2]]
    d = h[i+2] -h[i]
    min_d = min(d, min_d)
    
print(min_d)

Failing test case input:
5 5
14
15
11
9
12

Expected output:
6


Actual output:
3


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = []
min_d = 10 ** 10

h = [int(input()) for i in range(N)]
h = sorted(h)

for i in range(N-K+1) : 
    d = h[i+K-1] -h[i]
    min_d = min(d, min_d)
    
print(min_d)

Problem: p03208
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k=map(int, input().split())
h=[]
for i in range(n):
  h.append(int(input()))
h.sort()
ans=h[k-1]-h[0]
for i in range(1,n-k):
  ans=min(ans,h[i+k-1]-h[i])
print(ans)

Failing test case input:
5 3
0
15
11
15
12

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n,k=map(int, input().split())
h=[]
for i in range(n):
  h.append(int(input()))
h.sort()
ans=h[k-1]-h[0]
for i in range(1,n-k+1):
  ans=min(ans,h[i+k-1]-h[i])
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
h =[]
dif = []
for n in range(0,N):
    h.append(int(input()))

h.sort()

m = 10**10

for i in range(0,N-K):
    m = min(m,abs(h[i] - h[i+K-1]))

print(m)


Failing test case input:
5 2
10
8
10
0
7

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
h =[]
dif = []
for n in range(0,N):
    h.append(int(input()))

h.sort()

m = 10**10

for i in range(0,N-K+1):
    m = min(m,abs(h[i] - h[i+K-1]))

print(m)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N, K = map(int, input().split())
    H = [int(input()) for i in range(N)]
    H.sort()
    mi = 10**9
    for i in range(N - K + 1):
        h_ = H[i:i+K]
        print(h_)
        if max(h_) - min(h_) < mi:
            mi = max(h_) - min(h_)
    print(mi)
if __name__ == "__main__":
    main()

Failing test case input:
5 3
14
15
17
14
12

Expected output:
1


Actual output:
[12, 14, 14]
[14, 14, 15]
[14, 15, 17]
1


Fixed submission (verdict: Accepted):
def main():
    N, K = map(int, input().split())
    H = [int(input()) for i in range(N)]
    H.sort()
    mi = 10**9
    for i in range(N - K + 1):
        diff = H[i+K-1] - H[i]
        if diff < mi:
            mi = diff
    print(mi)
if __name__ == "__main__":
    main()

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def christmasEve():
    N, K = map(int, input().split())
    h = [int(input()) for i in range(N)]
    strees = sorted(h)
    d = sorted([ y -x for x ,y in zip(strees, strees[1:])])
    print(sum([i for i in d[1:N]]))

if __name__ == "__main__":
    christmasEve()

Failing test case input:
4 3
18
21
2
0
10

Expected output:
18


Actual output:
19


Fixed submission (verdict: Accepted):
def christmasEve():
    N, K = map(int, input().split())
    h = [int(input()) for i in range(N)]
    strees = sorted(h)
    result=10**9
    for i in range(N-K+1):
        result = min(result, strees[i+K-1] - strees[i])
    print(result)

if __name__ == "__main__":
    christmasEve()

Problem: p03208
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, k = map(int, input().split())
trees = [0 for _ in range(n)]
for i in range(n):
    trees[i] = int(input())
trees = sorted(trees)

ans_list = []
for index, tree in enumerate(trees):
    if  k-1 <= index:
        print(tree)
        ans_list.append(tree-trees[index-(k-1)])
print(min(ans_list))


Failing test case input:
5 1
3
1
10
0
11

Expected output:
0


Actual output:
0
1
3
10
11
0


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
trees = [0 for _ in range(n)]
for i in range(n):
    trees[i] = int(input())
trees = sorted(trees)

ans_list = []
for index, tree in enumerate(trees):
    if  k-1 <= index:
        ans_list.append(tree-trees[index-(k-1)])
print(min(ans_list))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = sorted([int(input()) for i in range(N)])
l = []
for i in range(1, N):
    l += [h[i] - h[i-1]]
    
l.sort()
print(sum(l[:K-1]))

Failing test case input:
4 3
15
25
2
0
10

Expected output:
15


Actual output:
12


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = sorted([int(input()) for i in range(N)])

m = float('inf')

for i in range(N-K+1):
    m = min(m, h[i+K-1] - h[i])

print(m)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = (int(x) for x in input().split())

trees = list()

for i in range(N):
  trees.append(int(input()))
  
trees = sorted(trees)
diff_list = []

for i in range(N - 2):
  diff = trees[i + 2] - trees[i]
  diff_list.append(diff)
  
print(min(diff_list))

Failing test case input:
5 2
8
8
10
0
11

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
N, K = (int(x) for x in input().split())

trees = list()

for i in range(N):
  trees.append(int(input()))
  
trees = sorted(trees)
diff_list = []

for i in range(N - K + 1):
  diff = trees[i + K - 1] - trees[i]
  diff_list.append(diff)
  
print(min(diff_list))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int, input().split())
lst = [int(input()) for i in range(N)]
lst.sort(reverse=True)

diff_lst = [lst[i] - lst[i+2] for i in range(N-2)]
print(min(diff_lst))

Failing test case input:
5 4
10
21
39
0
8

Expected output:
21


Actual output:
10


Fixed submission (verdict: Accepted):
N,K = map(int, input().split())
lst = [int(input()) for i in range(N)]
lst.sort(reverse=True)

diff_lst = [lst[i] - lst[i+K-1] for i in range(N-K+1)]
print(min(diff_lst))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())

H = sorted([int(input()) for i in range(N)])

diff_min = H[2] - H[0]

for i in range(0,N - K + 1):

  diff = H[i + K - 1] - H[i]
  if diff <= diff_min:
    diff_min = diff
    
print(diff_min)

Failing test case input:
5 4
10
30
28
0
8

Expected output:
22


Actual output:
10


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())

H = sorted([int(input()) for i in range(N)])

L = []

for i in range(0,N - K + 1):
  diff = H[i + K - 1] - H[i]
  L.append(diff)

    
print(min(L))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
S = S.split()
N = int(S[0])
K = int(S[1])
h = [int(input()) for i in range(N)]
h.sort()
ans1 = h[K-1] - h[0]
ans2 = h[N-1] - h[N-K]
if(ans1 < ans2):
    print(ans1)
else:
    print(ans2)


Failing test case input:
5 2
8
8
17
0
11

Expected output:
0


Actual output:
6


Fixed submission (verdict: Accepted):
S = input()
S = S.split()
N = int(S[0])
K = int(S[1])
h = [int(input()) for i in range(N)]
h.sort()
ans = 10**9 + 1
for i in range(N - K + 1):
    tmp = h[i + K - 1] - h[i]
    if(tmp < ans):
        ans = tmp
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N , K =map(int,input().split())
H = []
for i in range(N):
    H.append(input())
H =sorted(H)

ans = 1000000000
for j in range(N-K+1):
    ans=min(int(H[j+K-1])-int(H[j]),ans)

print(ans)

Failing test case input:
3 3
14
7
1
2
10

Expected output:
13


Actual output:
6


Fixed submission (verdict: Accepted):
N , K =map(int,input().split())
H = []
for i in range(N):
    H.append(int(input()))
H =sorted(H)

ans = 1000000000
for j in range(N-K+1):
    ans=min(int(H[j+K-1])-int(H[j]),ans)
    

print(ans)
Problem: p03208
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k = map(int,input().split())
L = []
for val in range(n):
    L.append(val)

L = sorted(L)
ans_L = []
for i in range(n-k+1):
    ans = L[i+k-1] - L[i]
    ans_L.append(ans)
print(min(ans_L))

Failing test case input:
4 3
18
21
21
0
10

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
L = []
for val in range(n):
    val = int(input())
    L.append(val)

L = sorted(L)
ans_L = []
for i in range(n-k+1):
    ans = L[i+k-1] - L[i]
    ans_L.append(ans)
print(min(ans_L))

Problem: p03208
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):


N,K=map(int,input().split())
H=[0]*N
for i in range(N):
    H[i]=int(input())
H.sort()
mae=H[K-1]-H[0]
usr=H[N-1]-H[N-1-K+1]

print(min(mae,usr))

Failing test case input:
5 3
10
21
6
0
6

Expected output:
4


Actual output:
6


Fixed submission (verdict: Accepted):


N,K=map(int,input().split())
H=[0]*N
for i in range(N):
    H[i]=int(input())
H.sort()
ans=float('inf')
for i in range(N-K+1):
    ans=min(ans,H[i+K-1]-H[i])
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int, input().split())
h = list(sorted([int(input()) for i in range(n)]))
ans = max(h)
for i in range(n-k+1):
    l = h[i:i+3]
    ans = min(ans,max(l)-min(l))
print(ans)

Failing test case input:
5 5
14
15
11
15
12

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
n,k = map(int, input().split())
h = list(sorted([int(input()) for i in range(n)]))
h.sort()
ans = h[n-1]+1
for i in range(n-k+1):
    ans = min(ans, h[i+k-1]-h[i])
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = list(map(int, input().split()))
H = sorted([int(input()) for _ in range(N)])

min_h = 1e15
for i in range(N-K+1):
    tmp = H[i+K-1] - H[i]
    if tmp < min_h:
        min_h = tmp


Failing test case input:
5 3
5
11
10
0
6

Expected output:
5


Actual output:

Fixed submission (verdict: Accepted):
N, K = list(map(int, input().split()))
H = sorted([int(input()) for _ in range(N)])

min_h = 1e15
for i in range(N-K+1):
    tmp = H[i+K-1] - H[i]
    if tmp < min_h:
        min_h = tmp
print(min_h)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b = map(int, input().split())
c = [int(input()) for _ in range(a)]
c.sort()
d = 0
for i in range(2, a):
    if d == 0:
        d = abs(c[i] - c[i-b+1])
    else:
        if abs(c[i] - c[i-b+1]) < d:
            d = abs(c[i] - c[i-2])
print(d)


Failing test case input:
5 2
3
6
3
0
11

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
a, b = map(int, input().split())
c = [int(input()) for _ in range(a)]
c.sort()
d = -1
for i in range(b-1, a):
    if d == -1:
        d = abs(c[i] - c[i-b+1])
    else:
        if abs(c[i] - c[i-b+1]) < d:
            d = abs(c[i] - c[i-b+1])
print(d)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = list([int(input()) for i in range(N)])
h = sorted(h)
print(min(max(h[:K])-min(h[:K]),max(h[-K:])-min(h[-K:])))

Failing test case input:
5 3
10
12
11
16
12

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = list([int(input()) for i in range(N)])
h = sorted(h)
ans = 10**9

for i in range(N-K+1):
    ans = min(ans, h[i+K-1]-h[i])
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
H = sorted([int(input()) for _ in range(n)])
ans = float("INF")
for i in range(0,n - k + 1):
  print(i)
  selected = H[i:k + i]
  ans = min(ans,max(selected) - min(selected))
print(ans)

Failing test case input:
3 3
10
7
5
1
5

Expected output:
5


Actual output:
0
5


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
H = sorted([int(input()) for _ in range(n)])
ans = float("INF")
for i in range(n - k + 1):
  diff = H[k + i -1] - H[i]
  ans = min(ans,diff)
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
l = input().split(" ")
alltrees = int(l[0])
lighttrees = int(l[1])
tl = []
for i in range(alltrees):
    tl.append(int(input()))
tl= sorted(tl,reverse=True)
h=0
i = 0
while(i<alltrees-lighttrees):
    h = min(tl[i]-tl[i+lighttrees-1], tl[i+1]-tl[i+lighttrees])
    i+=1
print(h)

Failing test case input:
3 3
5
7
0
1
7

Expected output:
7


Actual output:
0


Fixed submission (verdict: Accepted):
l = input().split(" ")
trees = int(l[0])
lights = int(l[1])
ls=[]
for i in range(trees):
    ls.append(int(input()))
ls = sorted(ls,reverse=True)
h = ls[0]-ls[lights-1]
for i in range(trees -lights):
   if h >min(ls[i]-ls[i+lights-1],ls[i+1]-ls[i+lights]):
       h = min(ls[i]-ls[i+lights-1],ls[i+1]-ls[i+lights])
print(h)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
min = 1024
for i in range(len(h)-2):
    if h[i+2] - h[i] < min:
        min = h[i+2] - h[i]
print(min)


Failing test case input:
5 2
8
8
10
0
7

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
min = h[k-1] - h[0]
for i in range(len(h)-k+1):
    dif = h[i+k-1] - h[i]
    if dif < min:
        min = dif
print(min)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
a=[]
for _ in range(n):
  a+=[int(input())]
a.sort()
s=10**9
for i in range(n-k):
  s=min(s,a[i+k]-a[i])
print(s)

Failing test case input:
5 3
5
11
10
0
6

Expected output:
5


Actual output:
6


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
a=[]
for _ in range(n):
  a+=[int(input())]
a.sort()
s=10**9
for i in range(n-k+1):
  s=min(s,a[i+k-1]-a[i])
print(s)
Problem: p03208
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,k = map(int,input().split())
h = sorted([int(input()) for _ in range(n)])
ans = h[2]-h[0]
for i in range(n-k+1):
    m = h[i+k-1]-h[i]
    ans = min(m,ans)
print(ans)

Failing test case input:
5 5
0
53
20
25
-1

Expected output:
54


Actual output:
21


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
h = sorted([int(input()) for _ in range(n)])
ans = h[k-1]-h[0]
for i in range(n-k+1):
    m = h[i+k-1]-h[i]
    ans = min(m,ans)
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
tree_list = [int(input()) for _ in range(N)]
tree_list = sorted(tree_list)
ans = 10**9
for i in range(N-K-1):
    compare = tree_list[i+K]-tree_list[i]
    if ans > compare:
        ans = compare
print(ans)
    

Failing test case input:
5 4
10
30
17
0
8

Expected output:
17


Actual output:
1000000000


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
tree_list = [int(input()) for _ in range(N)]
tree_list = sorted(tree_list)
ans = 10**9
for i in range(N-K+1):
    compare = tree_list[i+K-1]-tree_list[i]
    if ans > compare:
        ans = compare
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
hn = []
for i in range(N):
  hn.append(int(input()))
hn = sorted(hn,reverse=True)
min = 99999999
for i in range(N-K+1):
  print("hn[i] is {} , hn[K+i] is {}".format(hn[i],hn[K+i-1]))
  if min > (hn[i]-hn[K+i-1]):
    min = hn[i]-hn[K+i-1]
print(min)


Failing test case input:
4 3
10
21
21
-1
10

Expected output:
11


Actual output:
hn[i] is 21 , hn[K+i] is 10
hn[i] is 21 , hn[K+i] is -1
11


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
hn = []
for i in range(N):
  hn.append(int(input()))
hn = sorted(hn,reverse=True)
min = 10**9+7
for i in range(N-K+1):

  if min > (hn[i]-hn[K+i-1]):
    min = hn[i]-hn[K+i-1]
print(min)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
A = [int(input()) for i in range(n)]
A.sort()
print(A[-1]-A[-k])

Failing test case input:
5 3
10
12
11
16
12

Expected output:
1


Actual output:
4


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
A = [int(input()) for i in range(n)]
A.sort()
print(min(A[i+k-1] - A[i] for i in range(n-k+1)))

Problem: p03208
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = [int(x) for x in input().split()]
H = sorted([int(input()) for _ in range(N)])
D = [-1] * (N-1)
for i in range(N-1):
    D[i] = H[i+1] - H[i] 
print(sum(sorted(D)[:(K-1)]))


Failing test case input:
4 3
10
38
31
0
6

Expected output:
28


Actual output:
17


Fixed submission (verdict: Accepted):
N, K = [int(x) for x in input().split()]
H = sorted([int(input()) for _ in range(N)])
minh = H[0]
H = [h-minh for h in H]
l = K-1
ans = H[-1]
for i in range(N-l):
    ans = min(ans, H[i+l]-H[i])
print(ans)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]

h = sorted(h)
ans = 10**9
for i in range(N-K+1):
    if ans > h[i+K-1] - h[i]:
        ans = h[i+K-1] - h[i]
    print(i, ans)

print(ans)


Failing test case input:
5 2
8
8
17
0
21

Expected output:
0


Actual output:
0 8
1 0
2 0
3 0
0


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]

h = sorted(h)
ans = 10**9
for i in range(N-K+1):
    if ans > h[i+K-1] - h[i]:
        ans = h[i+K-1] - h[i]

print(ans)

Problem: p03208
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,n = map(int,input().split())


N = [int(input()) for i in range(N)]
N = sorted(N)
Q = []
for i in range(len(N)-n+1):
	max1 = int(*N[i+n-1:i+n])
	min1 = int(*N[i:i+1])
	Q.append(max1 - min1)
print(max(Q))

Failing test case input:
5 3
10
15
11
14
12

Expected output:
2

Actual output:
3


Fixed submission (verdict: Accepted):
N,n = map(int,input().split())
 
 
N = [int(input()) for i in range(N)]
N = sorted(N)
Q = []
for i in range(len(N)-n+1):
	max1 = int(*N[i+n-1:i+n])
	min1 = int(*N[i:i+1])
	Q.append(max1 - min1)
print(min(Q))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


import sys

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n = hoge[0]
k = hoge[1]

h=[]
for i in range(0,n):
	tmp = int(input())
	h.append(tmp)

h.sort()


sum=0
for i in range(0,k):
	sum += h[i]
minsum=sum
for i in range(0,n-k):
	sum += h[i+k]
	sum -= h[i]
	minsum = min(minsum,sum)
print(minsum)

Failing test case input:
3 3
14
13
0
1
10

Expected output:
14


Actual output:
27


Fixed submission (verdict: Accepted):


import sys

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n = hoge[0]
k = hoge[1]

h=[]
for i in range(0,n):
	tmp = int(input())
	h.append(tmp)

h.sort()




res=h[k-1]-h[0]


for i in range(1,n-k+1):
	res = min(res,h[k+i-1]-h[i])
	
print(res)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = list(map(int, input().split()))
h = [int(input()) for i in range(n)]
h = sorted(h)[:k]
  
print(max(h) - min(h))

Failing test case input:
5 3
5
7
10
0
6

Expected output:
2


Actual output:
6


Fixed submission (verdict: Accepted):
n, k = list(map(int, input().split()))
h = [int(input()) for i in range(n)]
h = sorted(h)
print(min([h[i+k-1] - h[i] for i in range(n - k+1)]))

Problem: p03208
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,k = map(int,input().split())
li = []
lia = [0]*(n-2)
for i in range(n):
    li.append(int(input()))
li.sort()
for i in range(n-2):
    lia[i] += li[i+2] - li[i]
print(min(lia))

Failing test case input:
5 1
3
1
10
0
11

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
li = []
lia = [0]*(n-k+1)
for i in range(n):
    li.append(int(input()))
li.sort()
for i in range(n-k+1):
    lia[i] += li[i+k-1] - li[i]
print(min(lia))
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

N, K = list(map(int,input().split()))
H = []
for i in range(N):
    H.append(int(input()))
H = sorted(H,reverse = False)
C = Counter(H)
CH = list(C.values()) 

cnt = 0
for i in range(len(CH)):
    if CH[i] >= K:
        cnt += 1
        break
if cnt != 0:
    print('0')
else:
    print(H[K-1] - H[0])


Failing test case input:
5 3
0
15
20
25
12

Expected output:
8


Actual output:
15


Fixed submission (verdict: Accepted):
from collections import Counter

N, K = list(map(int,input().split()))
H = []
for i in range(N):
    H.append(int(input()))
H = sorted(H,reverse = False)
C = Counter(H)
CH = list(C.values()) 

cnt = 0
for i in range(len(CH)):
    if CH[i] >= K:
        cnt += 1
        break
ans = 999999999999999
for i in range(N-K+1):
    ans = min(ans,H[K-1+i] - H[i]) 

if cnt != 0:
    print('0')
else:
    print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from statistics import mean, median,variance,stdev
import sys
import math

x = input().split()





a = []
b = int(x[0])
num = int(x[1])
for i in range(b):
    a.append(int(input()))
a = sorted(a)
min = a[num-1]-a[0]
for i in range(num,b):
    if min > a[i]-a[i-num]:
        min = a[i]-a[i-num]
if min > a[b-1]-a[b-num]:
    min = a[b-1]-a[b-num]
print(min)


Failing test case input:
5 3
10
21
15
0
8

Expected output:
7


Actual output:
10


Fixed submission (verdict: Accepted):
from statistics import mean, median,variance,stdev
import sys
import math

x = input().split()





a = []
b = int(x[0])
num = int(x[1])
for i in range(b):
    a.append(int(input()))
a = sorted(a)
min = a[num-1]-a[0]
for i in range(num,b):
    if min > a[i]-a[i-num+1]:
        min = a[i]-a[i-num+1]
if min > a[b-1]-a[b-num]:
    min = a[b-1]-a[b-num]
print(min)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = (int(x) for x in input().split())
h = [int(input()) for i in range(K)]
h.sort()
print(min(h[i+K-1] - h[i]) for i in range(N-K+1))

Failing test case input:
5 2
8
8
17
0
21

Expected output:
0


Actual output:
<generator object <genexpr> at 0x7f17f4ea8d60>


Fixed submission (verdict: Accepted):
N, K = (int(x) for x in 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)))
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

N, K = list(map(int,input().split()))
H = []
for i in range(N):
    H.append(int(input()))
H = sorted(H,reverse = False)
C = Counter(H)
CH = list(C.values()) 

cnt = 0
for i in range(len(CH)):
    if CH[i] >= K:
        cnt += 0
        break
if cnt != 0:
    print('0')
else:
    print(H[K-1] - H[0])


Failing test case input:
5 4
10
30
28
0
8

Expected output:
22


Actual output:
28


Fixed submission (verdict: Accepted):
from collections import Counter

N, K = list(map(int,input().split()))
H = []
for i in range(N):
    H.append(int(input()))
H = sorted(H,reverse = False)
C = Counter(H)
CH = list(C.values()) 

cnt = 0
for i in range(len(CH)):
    if CH[i] >= K:
        cnt += 1
        break
ans = 999999999999999
for i in range(N-K+1):
    ans = min(ans,H[K-1+i] - H[i]) 

if cnt != 0:
    print('0')
else:
    print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
heights = [int(input()) for i in range(N)]
heights.sort()

diff = heights[K-1] - heights[0]
ans = diff

for i in range(N)[1:N-K+1]:
  diff = heights[i+K-1] - heights[i-1]
  ans = min(ans, diff)
print(ans)
  


Failing test case input:
5 2
12
7
10
0
7

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
heights = [int(input()) for i in range(N)]
heights.sort()

diff = heights[K-1] - heights[0]
ans = diff

for i in range(N)[1:N-K+1]:
  diff = heights[i+K-1] - heights[i]
  ans = min(ans, diff)
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
d = [h[i+1]-h[i] for i in range(0, len(h)-1)]
S = 0
for i in range(k-1):
    S += d[i]
ans = 1000000000
for i in range(0, n-k):
    SS = S + d[i+k-1] - d[i]
    if SS <= S:
        ans = SS
print(ans)


Failing test case input:
3 3
14
7
1
2
10

Expected output:
13


Actual output:
1000000000


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
d = [h[i+1]-h[i] for i in range(0, len(h)-1)]
S = 0
for i in range(k-1):
    S += d[i]
ans = S
for i in range(0, n-k):
    SS = S + d[i+k-1] - d[i]
    if SS <= ans:
        ans = SS
    S = SS
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = [int(c) for c in input().split()]
h = [int(input()) for _ in range(n)]

h.sort()

min_d = 100000
for i in range(n-k):
    d = h[i+k-1] - h[i]
    if d < min_d:
        min_d = d

print(min_d)


Failing test case input:
5 3
5
7
5
7
7

Expected output:
0

Actual output:
2


Fixed submission (verdict: Accepted):
n, k = [int(c) for c in input().split()]
h = [int(input()) for _ in range(n)]

h.sort()

min_d = 1000000000
for i in range(n-k+1):
    d = h[i+k-1] - h[i]
    if d < min_d:
        min_d = d

print(min_d)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,(input().split()))
h=[int(input()) for i in range(n)]

q=sorted(h)
ansList=[]
for c,d in zip(q,q[k-1:]):
  print(c,d)
  ansList.append(d-c)

print(min(ansList))

Failing test case input:
4 3
10
38
19
0
6

Expected output:
19


Actual output:
0 19
10 38
19


Fixed submission (verdict: Accepted):
n,k=map(int,(input().split()))
h=[int(input()) for i in range(n)]

q=sorted(h)
ansList=[]
for c,d in zip(q,q[k-1:]):
  ansList.append(d-c)

print(min(ansList))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
print(N, K)
t = [int(input()) for i in range(N)]
t.sort(reverse = True)

l = []

for j in range(N-K+1):
    l.append(t[j] - t[j+K-1])
print(min(l))


Failing test case input:
5 3
5
2
2
0
6

Expected output:
2


Actual output:
5 3
2


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
t = [int(input()) for i in range(N)]
t.sort()
l = []

for j in range(N-K+1):
    l.append(t[j+K-1] - t[j])

print(min(l))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input().split(" ")
N = int(s[0])
K = int(s[1])

h = []
for i in range(N) : 
    s = input()
    h.append(int(s))
    
h = sorted(h)
minDiff = h[len(h) - 1] - h[0]
for i in range(N) : 
    try : 
        diff = h[len(h) - K + i] - h[i]
        minDiff = min(minDiff , diff)
    except : 
        continue
print(minDiff)

Failing test case input:
3 3
10
15
33
14
12

Expected output:
23


Actual output:
0


Fixed submission (verdict: Accepted):
s = input().split(" ")
N = int(s[0])
K = int(s[1])

h = []
for i in range(N) : 
    s = input()
    h.append(int(s))
    
h = sorted(h)
minDiff = h[len(h) - 1] - h[0]
for i in range(N) : 
    try : 
        diff = h[i + K - 1] - h[i]
        minDiff = min(minDiff , diff)
        
    except : 
        if i == 0 : minDiff = 0
        continue
print(minDiff)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import heapq

def main():
    n,k = map(int,input().split())
    tree_heights = []

    for i in range(n):
        tree_heights.append(int(input()))
    tree_heights.sort(reverse = True)
    tree_diffs = [0]
    first = tree_heights.pop()
    while tree_heights:
        second = tree_heights.pop()
        tree_diffs.append(abs(first-second))
        first = second

    tree_diffs.sort()

    
    
    print(sum(tree_diffs[0:k]))





if __name__ == '__main__':
    main()


Failing test case input:
4 3
15
25
2
0
10

Expected output:
15


Actual output:
12


Fixed submission (verdict: Accepted):
import heapq

def main():
    n,k = map(int,input().split())
    tree_heights = []

    for i in range(n):
        tree_heights.append(int(input()))
    tree_heights.sort()
    

    mn = 1000000000000000000000000000000
    for i in range(n-k+1):
        
        mn = min(abs(tree_heights[i]-tree_heights[i+k-1]),mn)
    print(mn)

    
    
    





if __name__ == '__main__':
    main()
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N , M = (map(int , input().split()))
tree = []
for i in range(N):
    tree.append(int(input()))
sort_tree = sorted(tree , reverse = True)
print(max(sort_tree[:M]) - min(sort_tree[:M]))

Failing test case input:
5 4
10
30
17
0
8

Expected output:
17


Actual output:
22


Fixed submission (verdict: Accepted):
N , M = (map(int , input().split()))
tree = []
for i in range(N):
    tree.append(int(input()))
sort_tree = sorted(tree)
print(min([sort_tree[i+M-1] - sort_tree[i] for i in range(N-M+1)]))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=input().split()
n=[int(i) for i in n]
h=[0]*n[0]
for i in range(n[0]):
    h[i]=int(input())
h.sort()

q=-1
for i in range(len(h)-n[1]):
    a=h[i+n[1]-1]-h[i]
    if q==-1 or q>a:
        q=a
print(q)

Failing test case input:
3 3
10
15
33
14
12

Expected output:
23


Actual output:
-1


Fixed submission (verdict: Accepted):
n=input().split()
n=[int(i) for i in n]
h=[0]*n[0]
for i in range(n[0]):
    h[i]=int(input())
h.sort()
q=-1
for i in range(0,len(h)-n[1]+1):
    a=h[i+n[1]-1]-h[i]
    if q==-1 or q>a:
        q=a
print(q)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
NK = input().split(' ')
N, K = int(NK[0]), int(NK[1])
trees = []
for i in range(N):
  trees.append(int(input()))
trees.sort()
min = float("inf")
for i in range(N-K):
  h = trees[i+K-1]-trees[i]
  if h < min:
    min = h
print(min)

Failing test case input:
3 3
14
13
0
1
10

Expected output:
14


Actual output:
inf


Fixed submission (verdict: Accepted):
NK = input().split(' ')
N, K = int(NK[0]), int(NK[1])
trees = []
for i in range(N):
  trees.append(int(input()))
trees.sort()
min = float("inf")
for i in range(N-K+1):
  h = trees[i+K-1]-trees[i]
  if h < min:
    min = h
print(min)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
h=[0]*n
for i in range(n):
    h[i]=int(input())

ans=10**9
for i in range(n-k):
    ans= min(h[i+k]-h[i], ans)
print(ans)


Failing test case input:
5 2
3
6
10
0
11

Expected output:
1


Actual output:
-6


Fixed submission (verdict: Accepted):
n,k =map(int,input().split())
h=[0]*n
for i in range(n):
    h[i]=int(input())
h.sort()
ans=10**9
for i in range(n-k+1):
    ans= min(h[i+k-1]-h[i], ans)
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n,k=map(int,(input().split()))
a=[]
for i in range(n):
    a.append(int(input()))

a.sort()
min_high=1000000000000

for i in range(n-k):
    high=-a[i]+a[i+k-1]
    if high<min_high:
        min_high=high

print(min_high)

Failing test case input:
5 3
5
7
5
7
7

Expected output:
0

Actual output:
2


Fixed submission (verdict: Accepted):

n,k=map(int,(input().split()))
a=[]
for i in range(n):
    a.append(int(input()))

a.sort()
min_high=1000000000000

for i in range(n-k+1):
    high=-a[i]+a[i+k-1]

    if high<min_high:
        min_high=high

print(min_high)
Problem: p03208
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):


N,K=map(int,input().split())
H=[0]*N
for i in range(N):
    H[i]=int(input())
H.sort()
mae=H[K-1]-H[0]
usr=H[N-1]-H[N-K]
print(H,mae,usr)
print(min(mae,usr))

Failing test case input:
3 3
5
7
10
7
0

Expected output:
5


Actual output:
[5, 7, 10] 5 5
5


Fixed submission (verdict: Accepted):


N,K=map(int,input().split())
H=[0]*N
for i in range(N):
    H[i]=int(input())
H.sort()
ans=float('inf')
for i in range(N-K+1):
    ans=min(ans,H[i+K-1]-H[i])
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, k = na()
h = [ni() for i in range(n)]
h.sort()
d = [h[i] - h[i - 1] for i in range(1, n)]
d.sort()
ans = sum([d[i] for i in range(k - 1)])
print(ans)

Failing test case input:
4 3
10
21
21
0
10

Expected output:
11


Actual output:
10


Fixed submission (verdict: Accepted):
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, k = na()
h = [ni() for i in range(n)]
h.sort()
ans = min([h[i + k - 1] - h[i] for i in range(n - k + 1)])
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = data = list(map(int, input().split()))
h_list = list()

for _ in range(N):
    h_list.append(int(input()))

h_list.sort()

min_diff = 9999999999
for i in range(N - K):
    diff = abs(h_list[i] - h_list[i + K - 1])
    min_diff = diff if diff < min_diff else min_diff

print(min_diff)


Failing test case input:
3 3
5
7
10
7
0

Expected output:
5


Actual output:
9999999999


Fixed submission (verdict: Accepted):
N, K = data = list(map(int, input().split()))
h_list = list()

for _ in range(N):
    h_list.append(int(input()))

h_list.sort()

min_diff = 9999999999
for i in range(N - K + 1):
    diff = abs(h_list[i] - h_list[i + K - 1])
    min_diff = diff if diff < min_diff else min_diff

print(min_diff)

Problem: p03208
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math

n, k = list(map(int, input().split()))
h = [int(input()) for _ in range(n)]
h.sort()
ans = math.inf
for i in range(n - k):
    ans = min(ans, max(h[i : i + k]) - min(h[i : i + k]))

print(ans)


Failing test case input:
5 3
5
7
1
1
5

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
import math

n, k = list(map(int, input().split()))
h = [int(input()) for _ in range(n)]
h.sort()
ans = math.inf
for i in range(n - k + 1):
    ans = min(ans, h[i + k - 1] - h[i])

print(ans)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 1000000000
for i in range(K):
    if(K+i > N):
        break
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Failing test case input:
5 2
8
6
10
0
11

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 10000000000
loop = N-K+1
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]

h.sort()

ans = float("inf")

for i in range(K, N):
	ans = min(ans, h[i] - h[i - K])

print(ans)

Failing test case input:
5 3
10
12
11
16
12

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]

h.sort()

ans = float("inf")

for i in range(K - 1, N):
	ans = min(ans, h[i] - h[i - K + 1])

print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())

t = [int(input()) for i in range(N)]
t.sort(reverse = True)
difference = t[0] - t[K-1]
print(difference)

Failing test case input:
5 2
8
8
17
0
21

Expected output:
0


Actual output:
4


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
t = [int(input()) for i in range(N)]
t.sort()
l = []

for j in range(N-K+1):
    l.append(t[j+K-1] - t[j])

print(min(l))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())

H = [int(input()) for i in range(N)]

H = sorted(H)

diff_min = abs(H[2] - H[0])



for i in range(0,N - K + 1):

  diff = abs(H[i + K - 1] - H[i])
  if diff < diff_min:
    diff_min = diff
    
print(diff_min)

Failing test case input:
5 4
10
30
28
0
8

Expected output:
22


Actual output:
10


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())

H = sorted([int(input()) for i in range(N)])

L = []

for i in range(0,N - K + 1):
  diff = H[i + K - 1] - H[i]
  L.append(diff)

    
print(min(L))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
H = sorted([int(input()) for _ in range(N)])
print(min([H[i+2]-H[i] for i in range(N-2)]))

Failing test case input:
5 4
10
30
28
0
8

Expected output:
22


Actual output:
10


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
H = sorted([int(input()) for _ in range(N)])
print(min([H[i+K-1]-H[i] for i in range(N-K+1)]))