TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
import sys
input = sys.stdin.readline
n,m= map(int,input().split())

B = []
C = [0]*n
ans = 0
pna = 0
for i in range(m):
    A = list(map(str,input().split()))
    if A[0] not in B:
        if A[1]=="AC" :
            B.append(A[0])
            ans += 1
            pna += C[int(A[0])-1]
    	else:
      	  C[int(A[0])-1] += 1 
print(ans,pna)

import sys
input = sys.stdin.readline
n,m= map(int,input().split())
A = [ int(input()) for _ in range(n)]
a=sorted(A)
ans = 10 **10
for i in range(n-m+1):
    ans = min(abs(a[i+m-1] - a[i]),ans)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
def cChristmas(n, k, hl):


    hl.sort()
    ans = 10**10

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

    return ans

def main():
    n, k = map(int, input().split())
    hl = [int(input()) for i in range(n)]
    print(cChristmas(n, k, hl))

if __name__ == '__main__':
    main()


def cChristmas(n, k, hl):


    hl.sort()
    ans = 10**10

    for i in range(n-k+1):
        ans = min(ans, hl[i+k-1]-hl[i])

    return ans

def main():
    n, k = map(int, input().split())
    hl = [int(input()) for i in range(n)]
    print(cChristmas(n, k, hl))

if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
N ,K = map(int,input().split())
h = [int(input()) for i in range(N)]
h.sort()
# print(h)
min=h[N-1]
for i in range(N):
  if(i+K>N):
    break
    tmp = h[i+K-1]-h[i]
    if(min>tmp):
      min = tmp
print(min)

N ,K = map(int,input().split())
h = [int(input()) for i in range(N)]
h.sort()
# print(h)
min=h[N-1]
for i in range(N):
  if(i+K>N):
    break
  tmp = h[i+K-1]-h[i]
  if(min>tmp):
    min = tmp
print(min)

Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
N, K = map(int,input().split())
h = [int(input()) for i in range(N)].sort()
# print(h)

MIN = 10**10
for i in range(N-K):
	if h[i+K-1] - h[i] <= MIN:
		MIN = h[i+K-1] - h[i]
#	print(i,h[i],h[i+K-1])
print(MIN)



N, K = map(int,input().split())
h = [0 for i in range(N)]
for i in range(N):
	h[i] = int(input())
h.sort()
# print(h)

MIN = 10**10
for i in range(N-K+1):
	if h[i+K-1] - h[i] <= MIN:
		MIN = h[i+K-1] - h[i]
# print(i,h[i],h[i+K-1])
print(MIN)



Verdicts: Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
N,K = map(int,input().split())
h = [int(input()) for _ in range(N)]
h.sort()
ans = 1e10
for i in range(N-K+1):
    tmp = h[i:i+K]
    print(tmp)
    ans = min(ans,max(tmp)-min(tmp))


print(ans)

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

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
import numpy as np
N = int(input())
K = int(input())

e = [0]*N

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

for i in range(N):
    print("i",i)
    for j in range(N):      
        if e[i] < e[j]:
            tmp = e[i]
            e[i] = e[j]
            e[j] = tmp

f = [0]*(N - K + 1)
for i in range(N-K+1):
    f[i] = e[K + i - 1] - e[i]

print(np.min(np.array(f)))

import numpy as np
N = int(input())
K = int(input())

e = [0]*N

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

for i in range(N):
    for j in range(N):      
        if e[i] < e[j]:
            tmp = e[i]
            e[i] = e[j]
            e[j] = tmp

f = [0]*(N - K + 1)
for i in range(N-K+1):
    f[i] = e[K + i - 1] - e[i]

print(np.min(np.array(f)))

import numpy as np
N,K=input().split()
N = int(N)
K = int(K)
e = [0]*N

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


#    for j in range(N):      
#        if e[i] < e[j]:
#            tmp = e[i]
#            e[i] = e[j]
#            e[j] = tmp

e = list(sorted(e))

f = [0]*(N - K + 1)
for i in range(N-K+1):
    f[i] = e[K + i - 1] - e[i]

print(np.min(np.array(f)))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
N, K = map(int, input().split())
hs = sorted([int(input()) for _ in range(N)])[::-1]
# N, K = 5, 3
# hs = [15, 14, 12, 11, 10]

min_diff = 10 ** 10
for i in range(0, N-K+1):
    tmp = hs[i:i+1]
    min_diff = min(min_diff, tmp[0] - tmp[-1])

print(min_diff)


N, K = map(int, input().split())
hs = sorted([int(input()) for _ in range(N)])[::-1]

min_diff = 10 ** 10
for i in range(N-K+1):
    min_diff = min(min_diff, hs[i] - hs[i+K-1])

print(min_diff)


Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
N, K, *h = map(int, open(0).read().split())
h.sort()
ans=float("inf")
for i in range(len(h)-k+1):
	ma = h[i+k-1]
	mi = h[i]
	ans = min(ans,ma-mi)

print(ans)

N, K, *h = map(int, open(0).read().split())
h = sorted(h)
ans=float("inf")
for i in range(len(h)-k+1):
	ma = h[i+k-1]
	mi = h[i]
	ans = min(ans,ma-mi)

print(ans)

n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
ans=float("inf")
for i in range(len(h)-k+1):
	ma = h[i+k-1]
	mi = h[i]
	ans = min(ans,ma-mi)

print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
n,k=map(int,input().split)
a=[]
c=[]
for i in range(n):
    b=int(input())
    a.append(b)
sorted(a)
for u in range(n-1):
    d=a[u+k-1]-a[u]
    c.append(d)
print(min(c))

n,k = map(int,input().split())
a=[]
c=[]
for i in range(n):
    b=int(input())
    a.append(b)
a.sort()
for u in range(n-k+1):
    d=a[u+k-1]-a[u]
    c.append(d)
print(min(c))

Verdicts: Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
,k=map(int,input().split())
a=[]
for x in range(n):
  a.append(int(input()))
ans=1000000009
a=sorted(a)
for y in range(n-k+1):
  ans=min(a[y+k-1]-a[y],ans)
  
print(ans)



n,k=map(int,input().split())
a=[]
for i in range(n):
  a.append(int(input()))
b=sorted(a)
print(b[n-1]-b[n-k+1])

n,k=map(int,input().split())
a=[]
for x in range(n):
  a.append(int(input()))
ans=1000000009
sorted(a)
for y in range(n-k):
  ans(a[y+k-1]-a[y],ans)
  
print(ans)

n,k=map(int,input().split())
a=[]
for i in range(n):
  a.append(input())
b=sort.a
print(b(n-1)-b(n-k+1))

n,k=map(int,input().split())
a=[]
for i in range(n):
  a.append(int(input()))
b=sorted(a)
print(b[n-1]-b[n-k+1])


n,k=map(int,input().split())
a=[]
for x in range(n):
  a.append(int(input()))
ans=1000000009
a=sorted(a)
for y in range(n-k+1):
  ans=min(a[y+k-1]-a[y],ans)
  
print(ans)



Verdicts: Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
N, M = list(map(int, input().split()))
K = [int(input()) for i in range(N)]
K = sorted(K)
print(min([K[i+M-1]-K[i] for i in range(N-M+1)])

N, M = list(map(int, input().split()))
K = [int(input()) for i in range(N)]
K = sorted(K)
print(min([K[i+M-1]-K[i] for i in range(N-M+1)]))

Verdicts: Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
n,k = map(int,input().split())
a = [int(input()) for i in range(n)]
b = [a[i+1]-a[i] for i in range(n-1)]
c = []
p = 0
m = 0
for i in range(n-k+1):
 for j in range(k-1):
  p += b[j+m]
 c.append(p)
 m += 1
 p = 0
print(min(c))
  


n,k = map(int,input())
a = [int(input()) for i in range(n)]
a.sort()
ans = []
for i in range(n-k+1):
 ans.append(a[i+k-1] - a[i])
print(min(ans))
 


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


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
import sys
N,K = list(map(int, input().strip().split(' ')))
trees = [int(line.strip()) for line in sys.stdin]
trees = sorted(trees)
print(min([trees[i+(N-1)]-trees[i] for i in range(len(trees)-(N-1))]))

import sys
N,K = list(map(int, input().strip().split(' ')))
trees = [int(line.strip()) for line in sys.stdin]
trees = sorted(trees)
print(min([trees[i+(K-1)]-trees[i] for i in range(len(trees)-(K-1))]))


Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
n, k = list(map(int, input().split()))
h = []
for i in range(n):
    h.append(int(input()))

m = 10e9
h.sort()
for i in range(len(h)-k):
    if h[i+k-1]-h[i] <= m:
        print(h[i+k-1],h[i])
        m = h[i+k-1] - h[i]
print(m)


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

m = []
h.sort()
for i in range(len(h)-k+1):
    m.append(h[i+k-1] - h[i])
print(sorted(m)[0])

Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
d=[0]*(n-1)
for j in range(n-1):
  d[j+1]=d[j]+h[j+1]-h[j]
m=1000000001
for l in range(n-k):
  m=min(m,d[l+k-1]-d[l])
print(m)
  
  
  
  

n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
d=[0]*(n-1)
for j in range(n-1):
  d[j+1]=d[j]+h[j+1]-h[j]
m=1000000001
for l in range(1,n-k+1):
  m=min(m,d[l+k-1]-d[l])
print(m)
  
  
  
  


n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
d=[0]*(n-1)
for j in range(n-1):
  d[j+1]=d[j]+h[j+1]-h[j]
m=float('inf')
for l in range(1,n-k+1):
  m=min(m,d[l+k-1]-d[l])
print(m)
  
  
  
  


n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
d=[0]*n
for j in range(n-1):
  d[j+1]=d[j]+h[j+1]-h[j]
m=float('inf')
for l in range(n-k+1):
  m=min(m,d[l+k-1]-d[l])
print(m)
  
  
  
  


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):

N, K = map(int, input().split())

h = [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)


N, K = map(int, input().split())

h = [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(int(ans))

import numpy as np
N, K = map(int, input().split())

h = [int(input()) for i in range(N)]
h = np.array(h)
h_sort = np.sort(h)
h_diff = h_sort[1:] - h_sort[:N-1]
h_diff_sort = np.sort(h_diff)

print(np.sum(h_diff_sort[:K]))


N, K = map(int, input().split())

h = [int(input()) for i in range(N)]
h.sort()
ans = float('INF')
for i in range(N - K +1):
    ans = min(ans, h[i + K -1] - h[i])
    
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
n, k = map(int,input().split(" "))
trees = []
for i in range(n):
    trees.append(int(input()))

trees.sort()
min_val = 0
for i in range(len(trees) - 1):
    min_val = min(abs(trees[i+1] - trees[i]), min_val)
    
print(min_val)

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

min_val = 0
for i in range(len(trees) - 1):
    min_val = min(abs(trees[i+1] - trees[i]), min_val)
    
print(min_val)

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

trees.sort()
min_val = trees[k-1] - trees[0]
for i in range(1, n - k + 1):
    min_val = min(abs(trees[i+k-1] - trees[i]), min_val)
print(min_val)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
N, K = map(int, input().split())
lst = []
for i in range(N):
    x = int(input())
    lst.append(x)
lst.sort()
L = []
for i in range(N - K + 1):
    L.append(lst[i + K -1] - lst[i])
L.sort()
print(L)
print(L[0])

N, K = map(int, input().split())
lst = []
for i in range(N):
    lst.append(int(input()))
lst.sort()
dif = 10**9
for i in range(N):
    if lst[i+K-1] - lst[i] < dif:
        dif = lst[i+K-1] - lst[i]
print(dif)

N, K = map(int, input().split())
lst = []
for i in range(N):
    lst.append(int(input()))
lst.sort()
dif = 10**9
for i in range(N-K+1):
    if lst[i+K-1] - lst[i] < dif:
        dif = lst[i+K-1] - lst[i]
print(dif)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
N, K = map(int, input().split())
h = sorted([int(input()) for i in range(N)])
print(h)

inf = 10**9
min_height = inf
for i in range(N-K+1):
    print(i+(K-1), h[i+(K-1)], i, h[i])
    min_height = min(min_height, h[i+(K-1)] - h[i])

print(min_height)


N, K = map(int, input().split())
h = sorted([int(input()) for i in range(N)])
# print(h)

inf = 10**9
min_height = inf
for i in range(N-K+1):
    
    min_height = min(min_height, h[i+(K-1)] - h[i])

print(min_height)


Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
# -*- coding: utf-8 -*-
"""
Created on Tue May 14 20:13:03 2019

@author: avina
"""

n,k = map(int, input().split())
l = []
for i in range(n):
    l.append(int(input()))
l.sort(reverse=True)
i = 0
mins = 1e6
while i < n - k +1:
  mins = min(mins, l[i+k-1] - l[i])
  i+=1
print(mins)

# -*- coding: utf-8 -*-
"""
Created on Tue May 14 20:13:03 2019

@author: avina
"""

n,k = map(int, input().split())
l = []
for i in range(n):
    l.append(int(input()))
l.sort()
i = 0
mins = 1e10
while i < n - k +1:
  mins = min(mins, l[i+k-1] - l[i])
  i+=1
print(mins)

Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
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+1):
    d = h[i+k] - h[i]
    if d < min_d:
        min_d = d

print(min_d)

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)

Verdicts: Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
n,k  = map(int,input().split())
l = sorted([int(input()) for i in range(n)])
ansl = []
for m in range(n-k+1):
  ansl.append(max(l[m:m+k-1])-min(l[m:m+k-1]))
print(min(ansl))

n,k  = map(int,input().split())
l = sorted([int(input()) for i in range(n)])
print(min(l[i+k-1] - l[i] for i in range(n-k+1)))

Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
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)))

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)))

Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
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 t < min:
        min = t
print(min)


n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
min = '100000'
for i in range(len(h)-k+1):
    if h[i+k-1] - h[i] < min:
        min = h[i+k-1] - h[i]
print(min)


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)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
N,K=map(int,input().split())
H=[int(input()) for i in range(N)]
A=sorted(H)[::-1]
print(A)
ans=10**9
for i in range(N-K+1):
  a=A[i]-A[i+K-1]
  print(a)
  ans=min(ans,a)
print(ans)

N,K=map(int,input().split())
H=[int(input()) for i in range(N)]
A=sorted(H)[::-1]
ans=10**9
for i in range(N-K+1):
  a=A[i]-A[i+K-1]
  ans=min(ans,a)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
(n, k) = [int(x) for x in input().split()]
banig = []
for x in range(n):
  banig.append(int(input()))
banig.sort()

difBanig = []
for mini, maxi in zip(range(0,n-k+1), range(n-k,n+1)):
  difBanig.append(banig[maxi] - banig[mini])
print(max(difBanig))

(n, k) = [int(x) for x in input().split()]
banig = []
for x in range(n):
  banig.append(int(input()))
banig.sort()

difBanig = []
for bot in range(n-k+1):
  difBanig.append(banig[bot+k-1] - banig[bot])

print(min(difBanig))

Verdicts: Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
x,y=list(map(int, input().split()))
list=[]
for i in range(x):
	list.append(int(input()))
list.sort()
print(list)
ans=10**10

for j in range(x-y+1):
	if list[j+y-1]-list[j]<ans:
		ans=list[j+y-1]-list[j]
print(ans)

x,y=list(map(int, input().split()))
list=[]
for i in range(x):
	list.append(int(input()))
list.sort()
ans=10**10

for j in range(x-y+1):
	if list[j+y-1]-list[j]<ans:
		ans=list[j+y-1]-list[j]
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
N,K = map(int,input().split())
H = sorted(int(input()) for _ in range(N))
ans = float("INF")
print(H)
for i in range(N-K):
    ans = min(H[i+K-1]-H[i],ans)
print(ans)

N,K = map(int,input().split())
H = sorted(int(input()) for _ in range(N))
ans = float("INF")
for i in range(N-K+1):
    ans = min(H[i+K-1]-H[i],ans)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
import numpy as np
N,K = map(int,input().split())
list = []
list_tmp = [0]*(K-1)
for i in range(N):
 list.append(int(input()))
 if i < N-K:
  list_tmp.append(list[i])
list = sorted(list);
list_tmp = sorted(list_tmp);
tmp = list[-K:];
tmp_list =  list_tmp[K:]
tmp = np.array(tmp)
tmp_list = np.array(tmp_list)
print(min(tmp - tmp_list))

import numpy as np
N,K = map(int,input().split())
list = []
for i in range(N):
 list.append(int(input()))
list = sorted(list);
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))

import numpy as np
N,K = map(int,input().split())
list = []
for i in range(N):
 list.append(int(input()))
list = sorted(list);
print(min(list[i+K-1] - list[i] for i in range(N-K+1)))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
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))

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)))

Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
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))

N, K = map(int, input().split())
h_in = []
[h_in.append(int(input())) for i in range(N)]

l = []
for i in range(N):
    a = []
    for j in range(N):
        if i != j and h[i]-h[j]>=0:
            a.append(h[i]-h[j])
    if len(a) >= K-1:
        l.append(a)

l2 = []
for i in range(len(l)):
    a = min(l[i])
    l[i].remove(a)
    l2.append(min(l[i]))
print(min(l2))

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))


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
import numpy as np

N,K = list(map(int, input().split(",")))
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
res = h[N-1] - h[0]
for i in np.arange(0,N-K+1,1):
    tmp = h[i+K-1] - h[i]
    if res > tmp:
        res = tmp
    
print(res)
    


import numpy as np

N,K = list(map(int, input().split()))
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
res = h[N-1] - h[0]
for i in np.arange(0,N-K+1,1):
    tmp = h[i+K-1] - h[i]
    if res > tmp:
        res = tmp
    
print(res)
    


Verdicts: Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
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)

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)

Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
n, k = map(int, input().split())
h = [0]*n
for i in range(n):
    h[i] = int(input())
print(h)
ans = 10**10
for i in range(n-k+1):
  if ans >= h[i+k-1] - h[i]:
    ans = h[i+k-1] - h[i]
print(ans)

n, k = map(int, input().split())
h = [0]*n
for i in range(n):
    h[i] = int(input())
ans = 10**10
for i in range(n-k+1):
  if ans >= h[i+k-1] - h[i]:
    ans = h[i+k-1] - h[i]
print(ans)

n, k = map(int, input().split())
h = [0]*n
for i in range(n):
    h[i] = int(input())
h.sort()
ans = 10**10
for i in range(n-k+1):
  if ans >= h[i+k-1] - h[i]:
    ans = h[i+k-1] - h[i]
    if ans == 0:
      break
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
N, K = list(map(int, input().split()))
H = []
for i in range(N):
        h = int(input())
        H.append(h)

H.sort()
ans = []

for i in range(N-K+1):
        print(i)
        dif = H[i+K-1] - H[i]
        ans.append(dif)
        
print(min(ans))
        

N, K = map(int, input().split())
H = []

for i in range(N):
        h = int(input())
        H.append(int(input()))

H.sort()

ans = []
for i in range(N-K-1):
        # print(i)
        dif = H[i+K-1] - H[i]
        ans.append(dif)

print(min(ans))
        

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

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
n,k=map(int,input().split())
h=list(int(input()) for _ in range(n))
a=[]
h.sort(reverse=True)
for i in range(n-k+1):
    if h[i]-h[i+k-1]==0:
        print(0)
        exit()
    a.append(h[i]-h[i+-1])
print(min(a))

n,k=map(int,input().split())
h=list(int(input()) for _ in range(n))
a=[]
h.sort(reverse=True)
for i in range(0,n-k+1):
    a.append(h[i]-h[i+k-1])
print(min(a))


Verdicts: Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
N, K = map(int, input().split())
h_list = []
for i in range(N):
    h = int(input())
    h_list.append(h)
h_list = sorted(h_list, reverse = True)
for i in range(N-K+1):
    cnt = h_list[i]-h_list[i+K-1]
    min1 = min(min1, cnt)
print(min1)

N, K = map(int, input().split())
h_list = []
min1 = 10**10
for i in range(N):
    h = int(input())
    h_list.append(h)
h_list = sorted(h_list, reverse = True)
for i in range(N-K+1):
    cnt = h_list[i]-h_list[i+K-1]
    min1 = min(min1, cnt)
print(min1)

Verdicts: Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
NK = list(map(int, input().split()))
a = [0]*NK[0]
for i in range(len(a)):
    a[i] = int(input())
a.sort()

b = [0]*NK[1]
offsets = [0]*(NK[0]-NK[1]+1)
for i in range(len(offsets)):
    for j in range(NK[1]):
        b[j] = a[i+j]
    offsets[i] = b[K-1] - b[0]

print(min(offsets))


NK = list(map(int, input().split()))
a = [0]*NK[0]
for i in range(len(a)):
    a[i] = int(input())
a.sort()
N = NK[0]
K = NK[1]

minimum = a[N-1]
for i in range(N-K+1):
    offset = a[i+K-1] - a[i]
    if minimum > offset:
        minimum = offset

print(minimum)


Verdicts: Runtime Error

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
N, K = 5,3
h = [5,7,5,7,7]


sorted_h = sorted(h)


ans = 10**8
for i in range(N - K + 1):
    ans = min(ans, sorted_h[i + K - 1] - sorted_h[i])
print(ans)

N, K = 5,3
h = [5,7,5,7,7]


sorted_h = sorted(h)


ans = 10**8
for i in range(N - K + 1):
    ans = min(ans, sorted_h[i + K - 1] - sorted_h[i])
print(ans)

n, k = map(int, input().split())
hhh = [int(input()) for _ in range(n)]
hhh.sort()
ans = float('inf')
for i in range(n - k + 1):
    ans = min(ans, hhh[i + k - 1] - hhh[i])
print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: In some other world, today is Christmas Eve.  There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.  He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.  More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

Submission attempts (in order):
n, k = map(int, input().split())
hl = [int(input()) for _ in range(n)]
hl.sort()
print(min([hl[k - 1 + i] - hl[i] for i in range(0, n - k + 1)))


n, k = map(int, input().split())
hl = [int(input()) for _ in range(n)]
hl.sort()
print(min([hl[k - 1 + i] - hl[i] for i in range(0, n - k + 1)]))


Verdicts: Runtime Error

Accepted