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):
n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
h.sort()
ans=0

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=[i for i in range(n)]
h.sort()
l=[]
for i in range(k-2):
  l.appwnd(abs(h[i]-h[i+k-1]))
print(min(l))

n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
h.sort()
ans=0

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=[int(input()) for _ in range(n)]
h.sort()
l=[]
for i in range(len(h)-k+1):
  l.append(abs(h[i]-h[i+k-1]))
print(min(l))


Verdicts: Wrong Answer

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,k = map(int,input().split())
a=[]
for i in range(n):
	a.append(int(input()))

sa = sorted(a)
v=1000000
for i in range(n-k+1):
	if v > sa[i+k-1]-sa[i] 
		v = sa[i+k-1]-sa[i]
print(v)

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

sa = sorted(a)
v=10**9
for i in range(n-k+1):
	if v > sa[i+k-1]-sa[i]:
		v = sa[i+k-1]-sa[i]
print(v)

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




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


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())
2 h = [int(input()) for i in range(N)]
3 h.sort()
4 print(min(h[i+K-1] - h[i] for i in range(N-K+1)))

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

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


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

print(min(max(h[j:j+k])-min(h[j:j+k])) for j in range(n-k+1))


n,k = map(int,input().split())
h = list(map(int, [input() for i in range(n)])).sort()
dif = []
for j in range(n-k+1):
  dif.appned(max(h[j:j+k-1])-min(h[j:j+k-1]))
print(min(dif))


n,k = map(int,input().split())
h = list(map(int, [input() for i in range(n)])).sort()
dif = []
for j in range(n-k+1):
  dif.appned(max(h[i:i+k-1])-min(h[i:i+k-1]))
print(min(dif))

n,k = map(int,input().split())
h = sorted(list(map(int, [input() for i in range(n)])))
print(min(h[j+k-1]-h[j] for j in range(n-k+1)))
#for j in range(n-k):
    
#print(ans)


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

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

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)
    

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):
from sys import stdin
N, K = [int(x) for x in stdin.readline().rstrip().split()]
h = [int(stdin.readline().rstrip()) for _ in range(N)]
h.sort()
diff = [h[k + K] - h[k] for k in range(N - K)]
diff.sort()
print(diff[0])


from sys import stdin
N, K = [int(x) for x in stdin.readline().rstrip().split()]
h = [int(stdin.readline().rstrip()) for _ in range(N)]
h.sort()
diff = [h[k + K - 1] - h[k] for k in range(N - K + 1)]
diff.sort()
print(diff[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, x = map(int, input().split(' '))
lst = []
for i in range(n):
  lst.append(int(input()))
  lst.sort()
  minn = 999999999999
  for i in range(0, n-x+1):
    if lst[i+x]-lst[i] < minn:
      minn = lst[i+x] - lst[i]
  print(minn)

n, x = map(int, input().split(' '))
lst = []
for i in range(n):
	lst.append(int(input()))
lst.sort()
minn = 999999999999
for i in range(n-1, x, -1):
	if lst[i]-lst[i-x] <= minn:
		minn = lst[i] - lst[i-x]
	if minn == 0:
		break
print(minn)

n, x = map(int, input().split(' '))
lst = []
for i in range(n):
	lst.append(int(input()))
lst.sort()
minn = 999999999999
for i in range(n-1, 0, -1):
	if lst[i]-lst[i-1] < minn:
		minn = lst[i] - lst[i-1]
	if minn == 0:
		break
print(minn)

n, x = map(int, input().split(' '))
lst = []
for i in range(n):
	lst.append(int(input()))
lst.sort()
minn = 999999999999
for i in range(n-1, x-1, -1):
	if lst[i]-lst[i-x+1] <= minn:
		minn = lst[i] - lst[i-x+1]
	if minn == 0:
		break
print(minn)

n, x = map(int, input().split(' '))
lst = []
for i in range(n):
	lst.append(int(input()))
lst.sort()
minn = 999999999999
for i in range(n-1, x, -1):
	if lst[i]-lst[i-x+1] <= minn:
		minn = lst[i] - lst[i-x+1]
	if minn == 0:
		break
print(minn)

n, m = map(int, input().split(' '))
lst = [int(input()) for i in range(n)]
lst.sort()
print(min(lst[i+m-1]-lst[i] for i in range(n-m+1)))

Verdicts: Runtime Error

Wrong Answer

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())
h = [int(input()) for _ in range(n)]
hMin = 10**9
for i in range(n - k + 1):
    if h[k + i - 1]-h[i] < hMin:
        hMin = h[k + i - 1]-h[i]
print(hMin)


n, k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)])
print(min(h[k+i-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()
ans = 1<<31
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 _ in range(N)]
h.sort()
ans = 1<<31
for i in range(N-K+1):
  ans = min(ans, h[i+K-1]-h[i])
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):
import numpy as np
from sys import stdin
N,K=[int(x) for x in stdin.readline().rstrip().split()]
data=[]
for i in range(N):
    data.append(int(input()))
data.sort()
data.reverse()
ans=float("inf")
for i in range(N-K+1):
    tmp=data[i]-data[i+K-1]
    if ans > tmp:

import numpy as np
from sys import stdin
N,K=[int(x) for x in stdin.readline().rstrip().split()]
data=[]
for i in range(N):
    data.append(int(input()))
data.sort()
data.reverse()
ans=float("inf")
for i in range(N-K+1):
    tmp=data[i]-data[i+K-1]
    if ans > tmp:
        ans=tmp
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):
N, K = map(int, input().split())
lengths = list(int(input()) for i in range(N))
sorted_lengths = sorted(lengthes)
min_score = 2**100

for i in range(N-K+1):
  score = sorted_lengths[i+K-1] - sorted_lengths[i]
  min_score = min(min_score, score)

print(min_score)

N, K = map(int, input().split())
lengths = list(int(input()) for i in range(N))
sorted_lengths = sorted(lengths)
min_score = 2**100

for i in range(N-K+1):
  score = sorted_lengths[i+K-1] - sorted_lengths[i]
  min_score = min(min_score, score)

print(min_score)

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 = sorted(h, reverse = True)
print(h)

diff = 10**9
for i in range(N-K+1):
    a = h[i]-h[i+K-1]
    if diff > a:
        diff = a
    if diff == 0:
        break
print(diff)

#C - Christmas Eve
N,K = map(int,input().split())
h = [int(input()) for _  in range(N)]
h = sorted(h, reverse = True)

diff = 10**9
for i in range(N-K+1):
    a = h[i]-h[i+K-1]
    if diff > a:
        diff = a
    if diff == 0:
        break
print(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 = map(int, input().split())
ls = k[int(input()) for _ in range(n)]
ls.sort()
tmp = 10 ** 9
for i in range(n-k+1):
    diff = ls[i+k-1] - ls[i]
    if diff < tmp:
        tmp = diff
print(diff)

n,k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
dis = []
for i, j in zip(h, h[1:]):
    dis += [j - i]
print(dis)
print(sum((sorted(dis)[:k-1])))

n, k = map(int, input().split())
ls = sorted([int(input()) for _ in range(n)])
ans = float('inf')

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

Verdicts: 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,s=map(int, input().split())
N=[]
for _ in range(n):
    N.append(int(input()))
N=sorted(N)
for i in range(s-1,len(N)):
    diff_list.append(N[i]-N[i-s+1])
print(min(diff_list))

n,s=map(int, input().split())
N=[]
for _ in range(n):
    N.append(int(input()))
N=sorted(N)
diff_list=[]
for i in range(s-1,len(N)):
    diff_list.append(N[i]-N[i-s+1])
print(min(diff_list))

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 = input()
NK = N.split(" ")
N = int(NK[0])
K = int(NK[1])

h = []
for i in range(N):
  h.append(int(input()))
    
h.sort()
ans = h[-1] - h[0]

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

NK = input()
NK = N.split(" ")
N = int(NK[0])
K = int(NK[1])


h = []
for i in range(N):
  h.append(int(input()))
  
  
h.sort()
ans = h[-1] - h[0]

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

NK = input()
NK = N.split(" ")
N = int(NK[0])
K = int(NK[1])

h = []
for i in range(N):
  h.append(int(input()))
  
  
h.sort()
ans = h[-1] - h[0]

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

NK = input()
NK = NK.split(" ")
N = int(NK[0])
K = int(NK[1])


h = []
for i in range(N):
  h.append(int(input()))
  
  
h.sort()
ans = h[-1] - h[0]

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

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())
tree = []
for i in range(N):
  tree.append(int(input()))
tree.sort()
mini = 1000000000
for i in range(N-K+1):
  mini = min(mini, tree[i+K-1]-[i])
print(mini)
  

N, K = map(int, input().split())
tree = []
for i in range(N):
  tree.append(int(input()))
tree.sort()
mini = 1000000000
for i in range(N-K+1):
  mini = min(mini, tree[i+K-1]-tree[i])
print(mini)
  

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):
if __name__ == "__main__":
    N, K = map(int, input().split())
    h = list()
    for i in range(N):
        h.append(int(input()))

    h = sorted(h)

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


if __name__ == "__main__":
    N, K = map(int, input().split())
    h = list()
    for i in range(N):
        h.append(int(input()))

    h = sorted(h)

    res = 10 ** 9 + 1
    for i in range(N-K+1):
        if res > h[i+K-1] - h[i]:
            res = h[i+K-1] - h[i]
    
    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())
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[k])
print(ans)

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)

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())
H = np.array([int(input()) for _ in range(0, N)])
H = np.sort(H)
#print(H)
H_diff = abs(H[1:]-H[:-1])
#print(H_diff)
best = np.sum(H_diff[0, K-1])
for i in range(0, len(H_diff)-K+2):
    #print(i)
    if np.sum(H_diff[i:i+K-1]) < best:
        #print(H_diff[i:i+K-1])
        best = np.sum(H_diff[i:i+K-1])
#print('best:{}'.format(best))
print(best)

import numpy as np
N, K = map(int,input().split())
H = np.array([int(input()) for _ in range(0, N)])
H = np.sort(H)
H_diff = abs(H[1:]-H[:-1])
#best = (H[-1] - H[0])*K
H_diff = np.sort(H_diff)



print(H_diff)
print(np.sum(H_diff[0:K-1]))

import numpy as np
N, K = map(int,input().split())
H = np.array([int(input()) for _ in range(0, N)])
H = np.sort(H)
H_diff = np.diff(H)
best = int(np.min(np.convolve((H_diff), np.ones(K-1), mode='valid')))
print(best)

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


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

from collections import Counter

N, K = map(int, input().split())
H = [ int(input()) for _ in range(N) ]

c = Counter(H)
#print(c)

t = []
for k, v in c.most_common():
    if K >= v:
        K -= v
        t.append(k)
    else:
        t.append(k)
        K = 0

    if K == 0:
        break

print(max(t) - min(t))


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N, K = map(int, input().split())
H = [ int(input()) for _ in range(N) ]

H.sort()

ans = INF
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):
N, K = map(int,input().split())
h = []
for i in range(N):
    x = int(input())
    h.append(x)

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

print(min(m))

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

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

print(min(m))

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())
ans=[]
for i in range(n):
    ans.append(int(input()))
ans.sort()
print(min(ans[i+k-1]-ans[i] for j in range(n-k+1)))



n,k=map(int,input().split())
ans=[]
for i in range(n):
    ans.append(int(input()))
ans.sort()
print(min(ans[j+k-1]-ans[j] for j in range(n-k+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())
h = list(map(int,input().split()))
h.sort(reverse = True)
l = [0]*(N-(K-1))
for i in range(N-(K-1)):
  l[i] = h[i]-h[i+K-1]
ans = min(l)
print(ans)

N,K = map(int,input().split())
h = list(map(int,input().split()))
h.sort()
ans = min(h[i]-h[i+K] for i in range(N-K))
print(ans)

N,K = map(int,input().split())
h = [int(input()) for i in range(N)]
h.sort(reverse = True)
l = [0]*(N-(K-1))
for i in range(N-(K-1)):
  l[i] = h[i]-h[i+K-1]
ans = min(l)
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):
# coding: utf-8
# Your code here!
N,K = [int(i) for i in input().split()]

l = [int(input()) for j in range(N)]
l = sorted(l)
dif = 1000000000
for a in range(N-K+1):
    d = l[a+K-1] - l[a]
    print(a)
    print(d)
    if dif >= d:
        dif = d

print(dif)


# coding: utf-8
# Your code here!
N,K = [int(i) for i in input().split()]

l = [int(input()) for j in range(N)]
l = sorted(l)
dif = 1000000000
for a in range(N-K+1):
    d = l[a+K-1] - l[a]
    #print(a)
    #print(d)
    if dif >= d:
        dif = d

print(dif)


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 collections
n,k = map(int, input().split())
h = [ int(input()) for _ in range(n) ]
h_cnt = collections.Counter(h)


cnt = 0
for num, value in h_cnt.most_common():
  if(cnt == 0):
    h_max = num
    remain = k - value
  else:
    remain -= value
  if(remain <= 0):
    print(abs(h_max - num))
    exit()
  cnt += 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):
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    K = int(input())
    h = []
    for _ in range(N):
      h.append(int(input()))
  else:
    # N = 5
    # K g= 3
    # h = [10,15,11,14,12]
    N = 5
    K = 3
    h = [5,7,5,7,7]

  h.sort()
  for i in range(0,len(h)-2):
    if i == 0:
      ans = (h[2] - h[1]) + (h[1] - h[0])
    else:
      tmp = (h[i+2] - h[i+1]) + (h[i+1] - h[i])
      if ans > tmp:
        ans = tmp
  
  print(ans)

main()

import sys
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N,K = map(int, input().split())
    h = []
    for _ in range(N):
      h.append(int(input()))
  else:
    N = 5
    K = 3
    h = [10,15,11,14,12]
    # N = 5
    # K = 3
    # h = [5,7,5,7,7]

  h.sort()  

  ans = (h[K-1] - h[0])
  
  max_i = len(h)-K+1
  for i in range(1,max_i):
    tmp = (h[i+K-1] - h[i])
    if ans > tmp:
      ans = tmp
    if ans == 0:
      print(ans)
      sys.exit()
  
  print(ans)

main()

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

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

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 heapq

n, k = map(int, input().split())

h = []
for _ in range(n):
    heapq.heappush(h, int(input()))

q = [heapq.heappop(h) for _ in range(k-1)]

ans = 1e9
while len(h):
    p = i % (k-1)
    s = q[p]
    e = heapq.heappop(h)
    q[p] = e
    ans = min(ans, e - s)

print(ans)


import heapq

n, k = map(int, input().split())
h = []
d = [0 for _ in range(n)]
ans = 1e9

for _ in range(n):
    # h.append(int(input()))
    heapq.heappush(h, int(input()))

h = [heapq.heappop(h) for _ in range(n)]

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

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):
n, k = map(int,input().split())
h = list(int(input()) for i in range(n))    
h=sorted(h)
x=[]
for i in range(n-k+1):
  b = h[i+k-1]-h[i]
x.append(b)
print(min(x))

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

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,p=map(int,input().split())

item=[]
for i in range(n):
    p=int(input())
    item.append(p)
    
item.sort()
temp=[]
for i in range(n-1):
    a=item[i+1]-item[i]
    temp.append(a)
    
temp.sort()
print(temp[0])

n,p=map(int,input().split())

item=[]
for i in range(n):
    b=int(input())
    item.append(b)
    
item.sort()
temp=[]

for i in range(n-p):
    a=item[i+p]-item[i]
    temp.append(a)
    
temp.sort()
print(temp[0])

n,p=map(int,input().split())

item=[]
for i in range(n):
    b=int(input())
    item.append(b)
    
item.sort()
temp=[]

for i in range(n-p+1):
    a=item[i+p-1]-item[i]
    temp.append(a)
    
temp.sort()
print(min(temp))

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 = [int(x) for x in input().split()]
H = [0]*N
for i in range(N):
  H[i] = int(input())
H.sort(reverse=True)
ans= H[0]-H[K-1]
print(ans)

N,K = [int(x) for x in input().split()]
H = [0]*N
for i in range(N):
  H[i] = int(input())
H.sort(reverse=True)
ans = 100000000000000000
for i in range(N-K+1):
  ans = min(ans,H[i]-H[i+K-1])
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 = input()
n_k_list =n_k.split(' ')

N = int(n_k_list[0])
K = int(n_k_list[1])

h_list = [0] * N
for i in range(N):
    h_list[i] = int(input())

sorted_h_list = sorted(h_list)
print(sorted_h_list)

# print(h_list)
min_dif = 1000000000
for i in range(N-K+1):
    start = i
    end = K - 1 + i
    # print('start,end', start, end)
    end_v = sorted_h_list[end]
    start_v = sorted_h_list[start]
    dif = end_v - start_v
    # print('dif', dif)
    
    if min_dif > dif:
        min_dif = dif

print(int(min_dif))

n_k = input()
n_k_list =n_k.split(' ')

N = int(n_k_list[0])
K = int(n_k_list[1])

h_list = [0] * N
for i in range(N):
    h_list[i] = int(input())

sorted_h_list = sorted(h_list)

min_dif = 1000000000
for i in range(N-K+1):
    start = i
    end = K - 1 + i

    end_v = sorted_h_list[end]
    start_v = sorted_h_list[start]
    dif = end_v - start_v

    if min_dif > dif:
        min_dif = dif

print(int(min_dif))

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):
5 3
5
7
5
7
7

N,K=map(int,input().split(' '))
h=sorted([int(input()) for i in range(N)])
ans = 10**9
for i in range(N-K+1):
    ans = min(ans,h[i+K-1]-h[i])
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):
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 == K):
        break
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

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

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

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

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)

Verdicts: Wrong Answer

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())
tree = [int(input()) for _ in range(n)]
tree.sort()
result = float('INF')
cumulative = [0]
for i in range(n - 1):
    cumulative.append(tree[i + 1] - tree[i])
for i in range(n - k):
    result = min(result, cumulative[i + k - 1] - cumulative[i])
print(result)


n, k = map(int, input().split())
tree = [int(input()) for _ in range(n)]
tree.sort()
result = float('INF')
cumulative = [0]
for i in range(n - 1):
    cumulative.append(tree[i + 1] - tree[i] + cumulative[i])
for i in range(n - k + 1):
    result = min(result, cumulative[i + k - 1] - cumulative[i])
print(result)


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()
ans = h[1] - h[0]
for j in range(0,k-n):
  if ans < h[j+k-1] - h[0]:
    ans = h[j+k-1] - h[0]
print(ans)

n,k = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort()
ans = h[k-1] - h[0]
for j in range(0,n-k+1):
  if  h[j+k-1] - h[j] < ans:
    ans = h[j+k-1] - h[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 = 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


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)


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):
def main():
  N, K = map(int, input().split(' '))
  
  
  
  
  trees = [int(input()) for _ in range(N)]
  trees.sort()
  trees = [n - trees[0] for n in trees]
  
  
  MIN = 100000000000000
  # print(trees)
  for n in range(K):
    t = trees[n+K-1] - trees[n]
    print(trees[n], trees[n+K-1])
    MIN = min(t, MIN)
  print(MIN)
main()

def main():
  N, K = map(int, input().split(' '))
  
  
  
  
  trees = [int(input()) for _ in range(N)]
  trees.sort()
  trees = [n - trees[0] for n in trees]
  
  
  # MIN = 100000000000000
  # print(trees)
  # for n in range(K):
  # for n in range(N - K + 1):
  #   t = trees[n+K-1] - trees[n]
  #   MIN = min(t, MIN)
  MIN = min([trees[n+K-1] - trees[n] for n in range(N-K+1)])
  print(MIN)

main()

Verdicts: Runtime Error

Accepted