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):
def main():
    n, k = Input()
    data = sorted(int(input()) for _ in range(n))
    print(min([data[i+k-1] - data[i] for i in range(n-k+1)]))
main()

def main():
    n, k = map(int, input().split(" "))
    data = sorted(int(input()) for _ in range(n))
    print(min([data[i+k-1] - data[i] for i in range(n-k+1)]))
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 = input().split()
print(n, k)
N = int(n)
K = int(k)

h_array = []
for i in range(N):
    tree = int(input())
    h_array.append(tree)

h_array.sort()


result = float("inf")

for i in range(k - 1, N):
    result = min(result, h_array[i] - h_array[i - k + 1])

print(result)


n, k = input().split()
print(n, k)
N = int(n)
K = int(k)

h_array = []
for i in range(N):
    tree = int(input())
    h_array.append(tree)

h_array.sort()


result = float("inf")

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

print(result)


n, k = input().split()
N = int(n)
K = int(k)

h_array = []
for i in range(N):
    tree = int(input())
    h_array.append(tree)

h_array.sort()


result = float("inf")

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

print(result)

n, k = input().split()
N = int(n)
K = int(k)

h_array = []
for i in range(N):
    tree = int(input())
    h_array.append(tree)

h_array.sort()


result = float("inf")

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

print(result)

Verdicts: Runtime Error

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 = (int(i) for i in input().split())

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


h.sort()
print(h)
smallest = 10**9

for i in range(N-K+1):
    print(h[i+K-1],h[i])
    diff = h[i+K-1] - h[i]
    if diff < smallest:
        smallest = diff

print(smallest)

N,K = (int(i) for i in input().split())

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

h.sort()

difference = []

for i in range(N-K+1):
    #difference.append(h[N-1-i] - h[K-1-i])
    difference.append(h[K-1+i]-h[i])
    
print(min(difference))

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 , M = (map(int , input().split()))
tree = []
for i in range(N):
    tree.append(int(input()))
sort_tree = sorted(tree , reverse = True)
print(max(sort_tree[:M]) - min(sort_tree[:M]))

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

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):
h,n = map(int,input().split())
h = [0]*n
for i in range(n):
    h[i] = int(input())
h.sort()
ans = float('inf')
for i in range(n-k):
    ans = min(ans,abs(h[i+k-1]-h[i])
print(ans)


n,k = map(int,input().split())
h = [int(input()) for _ 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: 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 = [int(s) for s in input().split(' ')]
 
h = []
while len(h) != N:
    heapq.heappush(h, int(input()))
  
min_height = 1000000000
h.sort()
for start in range(0, N - k + 1):
    end = start + k - 1
    diff = h[end] - h[start]
    if diff < min_height:
        min_height = diff
print(min_height)

import heapq
 
N, k = [int(s) for s in input().split(' ')]
 
h = []
while N > 0:
  heapq.heappush(h, int(input()))
  N -= 1
  
trees = heapq.nlargest(k, h)
if len(trees) <= 1:
  print(0)
else:
  print(trees[0] - trees[-1])

import heapq
 
N, k = [int(s) for s in input().split(' ')]
 
h = []
while N > 0:
  heapq.heappush(h, int(input()))
  N -= 1
  
trees = heapq.nlargest(k, h)
if len(trees) <= 1:
  print(0)
else:
  print(trees[-1] - trees[0])

import heapq

N, k = int(input()), int(input())

h = []
while N > 0:
  heapq.heappush(h, int(input()))
  N -= 1
  
trees = heapq.nlargest(k, h)
if len(trees) <= 1:
  print(0)
else:
  print(trees[-1] - trees[0])

N, k = [int(s) for s in input().split(' ')]
 
h = []
while len(h) != N:
    h.append(int(input()))
  
min_height = 1000000000
h.sort()
for start in range(0, N - k + 1):
    end = start + k - 1
    diff = h[end] - h[start]
    if diff < min_height:
        min_height = diff
print(min_height)

Verdicts: Runtime Error

Wrong Answer

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):
tree_num,choice_num = map(int,input().split())
tree_list = sorted([int(input()) for _ in range(tree_num)])
mi = 99999
for idx in range(tree_num-choice_num):
    cand = tree_list[idx+choice_num-1] - tree_list[idx]
    if cand < mi:
        mi = cand
print(cand)

tree_num,choice_num = map(int,input().split())
tree_list = sorted([int(input()) for _ in range(tree_num)])
mi = 999999999999999999999999
for idx in range(tree_num-choice_num+1):
    cand = tree_list[idx+choice_num-1] - tree_list[idx]
    if cand < mi:
        mi = cand
print(mi)

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

trees = []
for _ in range(0, n):
  trees.append(int(input()))
trees.sort()
trees.reverse()
ans = 100000000000
for i in range(0, n-k):
  ans = min(ans, trees[i] - trees[i+k-1])
print(ans)

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

trees = []
for _ in range(0, n):
  trees.append(int(input()))
trees.sort()
trees.reverse()
print(trees[0] - trees[n-k])

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

trees = []
for _ in range(0, n):
  trees.append(int(input()))
trees.sort()
trees.reverse()
ans = 100000000000
for i in range(0, n-k+1):
  ans = min(ans, trees[i] - trees[i+k-1])
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())
a = 1000000000
h = list(map(int, [input() for i in range(N)]))
h.sort()
print(h)
for i in range(N-K+1):
    a = min(a, h[i+K-1]-h[i])
print(a)


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(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):
start = list(map(int, input().split()))
n,k = start[0], start[1]

lst = [int(input()) for i in range(n)]

lst.sort()
lst.reverse()

diff_lst = list()
for i in range(n-k+1):
    diff_lst.append(lst[i] - lst[i+k-1])
min(diff_lst)

start = list(map(int, input().split()))
n,k = start[0], start[1]

lst = [int(input()) for i in range(n)]

lst.sort()
lst.reverse()

diff_lst = list()
for i in range(n-k+1):
    diff_lst.append(lst[i] - lst[i+k-1])
print(min(diff_lst))

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):
NK=int(input())
ListNK=NK.split() #ListNK[0]=N,[1]=K
N=ListNK[0]
K=ListNK[1]
Listh=[]
ListQ=[]
for i in range(0,N,1):
  hi=int(input())
  Listh.append(hi)

Listh.sort() 
for i in range(0,N-K+1,1):
  Q=int(Listh[K+i-1]-Listh[i]) 
  ListQ.append(Q)
ListQ.sort()
print(ListQ[0])


NK=int(input())
ListNK=NK.split() #ListNK[0]=N,[1]=K
N=int(ListNK[0])
K=int(ListNK[1])
Listh=[]
ListQ=[]
for i in range(0,N,1):
  hi=int(input())
  Listh.append(hi)

Listh.sort() 
for i in range(0,N-K,1):
  Q=int(Listh[K+i-1]-Listh[i]) 
  ListQ.append(Q)
ListQ.sort()
print(ListQ[0])


NK=input()
ListNK=NK.split() #ListNK[0]=N,[1]=K
N=int(ListNK[0])
K=int(ListNK[1])
Listh=[]
ListQ=[]
for i in range(0,N,1):
  hi=int(input())
  Listh.append(hi)

Listh.sort() 
for i in range(0,N-K+1,1):
  Q=int(Listh[K+i-1]-Listh[i]) 
  ListQ.append(Q)
ListQ.sort()
print(ListQ[0])


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())
arr=[int(input()) for _ in range(n)]
arr=sorted(arr)
ans=10**10
for i in range(n-k):
  ans=min(ans,arr[i+k]-arr[i])
print(ans)

n,k=map(int,input().split())
arr=[int(input()) for _ in range(n)]
arr=sorted(arr)
ans=10**10
for i in range(n-k):
  ans=min(ans,sum(arr[i:i+k]))
print(ans)

n,k=map(int,input().split())
arr=[int(input()) for _ in range(n)]
arr=sorted(arr)
ans=10**10
for i in range(n-k+1):
  ans=min(ans,arr[i+k-1]-arr[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())
h = list(map(int, input().split()))
h.sort()

for i in range(n-k+1):
    a = h[i+k-1]-h[i]
    ans = a if i == 0 else min(ans, a)

print(ans)


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

for i in range(n-k+1):
    a = h[i+k-1]-h[i-1]
    ans = a if i == 0 else min(ans, a)

print(ans)


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

for i in range(n-k+1):
    a = h[i+k-1]-h[i]
    ans = a if i == 0 else min(ans, a)

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):
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    h = [int(input()) for i in range(N)]
    H = sorted(h)
    ans = H[N-1] - H[N-K]
    print(ans)

if __name__ == '__main__':
    main()

import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    h = [int(input()) for i in range(N)]
    H = sorted(h)

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

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):
import random

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

tmp = random.sample(H,K)
scr = max(tmp) - min(tmp)
print(scr)


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

tmp = [H[i+K-1]-H[i] for i in range(N-K+1)]

print(min(tmp))


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=sorted(h)

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

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

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

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

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


# coding:utf-8
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
ans = h[0]

print(min(h[i + k - 1] - h[i] for i 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):
import itertools

def q49(n, k, h):
    h.sort()
    a = [h[i+k-1]-h[i] for i in range(n-1)]
    return min(a)
            
N, K = [int(i) for i in input().split()]
h = []
for _ in range(N):
    h.append(int(input()))
print(q49(N, K, h))

import itertools

def q49(n, k, h):
    h.sort()
    a = [h[i+k-1]-h[i] for i in range(n-k+1)]
    return min(a)
            
N, K = [int(i) for i in input().split()]
h = []
for _ in range(N):
    h.append(int(input()))
print(q49(N, K, h))

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 = 100000#int(input())
    H.append(h)

H = sorted(H)

tmp = 0
ans = H[-1]
for i in range(N-K+1):
    tmp = H[i+K-1] - H[i]
#    print(H[i:i+K])

    ans = min(ans, tmp)

print(ans)


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

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

H = sorted(H)

tmp = 0
ans = H[-1]
for i in range(N-K+1):
    tmp = H[i+K-1] - H[i]
#    print(H[i:i+K])

    ans = min(ans, tmp)

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 __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
# from itertools import accumulate
# from collections import deque
import random

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

n,k = map(int, input().split())
h = np.zeros(n, dtype = int)
for i in range(n):
    h[i] = int(input())

h.sort()

ll = np.zeros(n-k+1,dtype=int)
for i in range(n-(k-1)):
    ll[i] = abs(h[i] - h[i+(k-1)])
    
print(ll)
print(ll.min())
    
    

# np.sort(h)
# h.sort()
# print(h)




from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
# from itertools import accumulate
# from collections import deque
import random

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

n,k = map(int, input().split())
h = np.zeros(n, dtype = int)
for i in range(n):
    h[i] = int(input())

h.sort()

ll = np.zeros(n-k+1,dtype=int)
for i in range(n-(k-1)):
    ll[i] = abs(h[i] - h[i+(k-1)])
    

print(ll.min())
    
    

# np.sort(h)
# h.sort()
# print(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):
import itertools
min_all = 1000000
    
N,K = [int(i) for i in input().split(" ")]
H = [int(input()) for _ in range(N)]
H.sort()
print(H)
    
for i in range(N+1-K):
  min_now = H[K-1+i] - H[i]
  if min_all > min_now:
    min_all = min_now
print(min_all)
        

import itertools
min_all = 1000000000000000000000000
    
N,K = [int(i) for i in input().split(" ")]
H = [int(input()) for _ in range(N)]
H.sort()
    
for i in range(N+1-K):
  min_now = H[K-1+i] - H[i]
  if min_all > min_now:
    min_all = min_now
print(min_all)

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

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

trees = []

for i in range(N):
   trees.append(int(input()))


trees.sort(reverse=True)

diff_list =[]

for i in range(N-1):
   diff_list.append(trees[i]-trees[i+1])

diff_list.sort()


print(min(diff_list[:K]))



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

trees = []

for i in range(N):
    trees.append(int(input()))


trees.sort()

ans = 1000000000
for i in range(N-K+1):
    aa = trees[i+K-1]-trees[i]
    if aa < ans:
        ans = aa

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,m=map(int,input().split())
tree=[]
for i in range(n):
    tree.append(int(input()))
heikin=int(sum(tree)/len(tree))
for i in range(n):
    tree[i]=tree[i]-heikin
tree.sort()
tree.reverse()
print(tree)
print(abs(tree[1]-tree[m-1]))

n,k=map(int,input().split())
answer=0
tree=[]
def tree_keisan(x,y): 
    ans=tree[x+y-1]-tree[x]
    return ans
for i in range(n):
    tree.append(int(input()))
tree.sort()
answer=tree_keisan(0,k)
for i in range(n-k+1):
    sa=tree_keisan(i,k)
    if answer>sa:
        answer=sa
print(answer)


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 sys
sys.setrecursionlimit(10 ** 6)


def input():
    return sys.stdin.readline()[:-1]


N, K = map(int, input().split())
H = [0]*N
for i in range(N):
    H[i] = int(input())

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


import sys
sys.setrecursionlimit(10 ** 6)


def input():
    return sys.stdin.readline()[:-1]


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


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

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)]
ans = max(h) - min(h)
h.sort(reverse=True)

print(h)
h_n = []
for i in range(0,n):
    l = h[i:i+k]
    if len(l) == k:
        h_n.append(l)

seed = max(h)
for i in range(0,len(h_n)):
    high = max(h_n[i]) - min(h_n[i])
    if seed > high:
        seed = high

print(seed)

n, k = map(int,input().split())
h = [int(input()) for i in range(n)]
h.sort(reverse=True)

seed = h[0]
for i in range(0,n-k+1):
    high = h[i] - h[i+k-1]
    seed = min(high,seed)

print(seed)

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

a = [int(input()) for _ in range(n)]
a.sort()
b = 0
ans = []
print(a)
for i in range(n - k + 1):
    b = a[i + k - 1] - a[i]
    ans.append(b)
ans.sort()
print(ans[0])

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

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_li = [int(input()) for i in range(n)]
dp = [[-1]*1000000010]*100010

def dfs(i, choosed):
    if i == n:
        if len(choosed) != k:
            dif = 10000000010
        else:
            dif = max(choosed) - min(choosed)

    elif len(choosed) >= 2 and dp[len(choosed)][max(choosed)-min(choosed)] != -1:
        dif = dp[len(choosed)][max(choosed)-min(choosed)]
            
    elif len(choosed) == k:
        dif = max(choosed) - min(choosed)
    else:
        dif = min(
            dfs(i+1, choosed + [h_li[i]]),
            dfs(i+1, choosed)
        )

    return dif

print(dfs(0, []))

n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h = sorted(h)
dif = 10**9

for i in range(n-k+1):
    if dif > h[i+k-1] - h[i]:
        dif = h[i+k-1] - h[i]

print(dif)

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

x=[]
for i in range(n):
    x.append(int(input()))

x.sort(reverse=True)

print(x[0]-x[k])

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

x=[]
for i in range(n):
    x.append(int(input()))

x.sort()

y=[]

for j in range(n):
  p=x[j+k-1]-x[j]
  y.append(p)

y.sort()

print(y[0])

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

x=[]
for i in range(n):
    x.append(int(input()))

x.sort()

y=[]

for j in range(n-k+1):
  p=x[j+k-1]-x[j]
  y.append(p)

y.sort()

print(y[0])

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 = [int(input()) for _ in range(n)]
h.sort()

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


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

ans = max(h) - min(h)
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 = list(map(int, input().split()))
h = [int(input()) for i in range(N)]
candidate = None
h.sort()
for i in range(N-K+1):
    tmp = h[i+K+1] - h[i]
    if candidate == None or tmp < candidate:
        candidate = tmp
print(candidate)

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

import numpy as  np
import copy
for i in range(N-K+1):
    
    diff = 0
    print("h[i] is {}".format(h[i]))
    for j in range(K-1):
        if(h[i] >= h[j]):
            target = [a for a in h if a <= h[i] and a >= h[j]]
            print("0")
            exit()
        else :
            target = [a for a in h if a > h[i] and a < h[j]]
        media = (a.pop(np.abs(np.asarray(a) - h[i]).argmin()))
        choose_h =[h[i],h[j],media]
        diff = max(choose_h)-min(choose_h)
        if(diff < candidate):
            candidate = diff
print(candidate)

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

Verdicts: Runtime Error

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 = []
for i in range(N):
    h.append(int(input()))

h.sort()
ans = 1e9

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

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

h.sort()
ans = 1e9


for i in range(0,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=list(map(int,input().split()))
n,k=n_k[0],n_k[1]
h_list=[]
for i in range(n):
    h_list.append(int(input()))
h_list.sort()
max = 99999999
for i in range(n-k+1):
    if max>h_list[n-1]-h_list[n-k]:
        max=h_list[n-1]-h_list[n-k]
print(max)

n_k=list(map(int,input().split()))
n,k=n_k[0],n_k[1]
h_list=[]
for i in range(n):
    h_list.append(int(input()))
h_list=h_list.sort()
max = 99999999
for i in range(n-k+1):
    if max>h_list[i+k-1]-h_list[i]:
        max=h_list[i+k-1]-h_list[i]
print(max)
    


n_k = list(map(int, input().split()))
n, k = n_k[0], n_k[1]
tree_list = []
for i in range(n):
    tree_list.append(int(input()))
tree_list.sort()
min = 1000000001
for i in range(n-k+1):
    if tree_list[i+k-1]-tree_list[i] <= min:

        min = tree_list[i+k-1]-tree_list[i]
print(int(min))


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

n,k = map(int,input().split())
li=list(range(n))
for i in range(n):
    li[i]=int(input())
li.sort()
ans=100000000000
for i in range(n-k+1):
    if ans>(li[i+k-1]-li[i]):
        ans=li[i+k-1]-li[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):
l = input().split(" ")
alltrees = int(l[0])
lighttrees = int(l[1])
tl = []
for i in range(alltrees):
    tl.append(int(input()))
tl= sorted(tl,reverse=True)
h=0
i = 0
while(i<alltrees-lighttrees-1):
    h = min(tl[i]-tl[i+lighttrees-1], tl[i+1]-tl[i+lighttrees])
    i+=1
print(h)



l = input().split(" ")
alltrees = int(l[0])
lighttrees = int(l[1])
tl = []
for i in range(alltrees):
    tl.append(int(input()))
tl= sorted(tl,reverse=True)
h=0
while(i<=alltrees-lighttrees):
    h = min(tl[i]-tl[i+lighttrees-1], tl[i+1]-tl[i+lighttrees])
print(h)

l = input().split(" ")
alltrees = int(l[0])
lighttrees = int(l[1])
tl = []
for i in range(alltrees):
    tl.append(int(input()))
tl= sorted(tl,reverse=True)
tl.append(0)
h=0
i = 0
while():
    h = min(tl[i]-tl[i+lighttrees-1], tl[i+1]-tl[i+lighttrees])
    i+=1
    if(tl[i+lighttrees]==0):
        break
print(h)

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

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())
H = []
for i in range(N):
    h = int(input())
    H.append(h)
H = sorted(H)
mi = 10**9
for i in range(N-K+1):
    _ = H[i+K] - H[i]
    if mi > _:
        mi = _
print(mi)

N, K = map(int, input().split())
H = []
for i in range(N):
    h = int(input())
    H.append(h)
H = sorted(H)
mi = 10**9
for i in range(N-K):
    _ = H[i+K] - H[i]
    if mi > _:
        mi = _
print(mi)

N, K = map(int, input().split())
H = []
for i in range(N):
    h = int(input())
    H.append(h)
H = H.sorted()
mi = 10**9
for i in range(N-K+1):
    _ = H[i+K] - H[i]
    if mi > _:
        mi = _
print(mi)

N, K = map(int, input().split())
H = map(int, open(0))
H = H.sorted()
mi = 10**9
for i in range(N-K+1):
    _ = H[i+K] - H[i]
    if mi > _:
        mi = _
print(mi)

N, K = map(int, input().split())
H = []
for i in range(N):
    h = int(input())
    H.append(h)
H = sorted(H)
mi = 10**9
for i in range(N-K+1):
    _ = H[i+(K-1)] - H[i]
    if mi > _:
        mi = _
print(mi)

Verdicts: Runtime Error

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

an.sort()
dn = [-1 for _ in range(n - k + 1)]
for i in range(n - k + 1):
  dn[i] = an[i+k] - an[i]

print(min(dn))

  

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

an.sort()
dn = [-1 for _ in range(n - k + 1)]
for i in range(n - k + 1):
  dn[i] = an[i+k-1] - an[i]

print(min(dn))

  

Verdicts: Runtime Error

Accepted