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())
tree = []
diff = 10 ** 9
for n in range(N):
    tree.append(int(input()))
tree.sort()
for i in range(N - (K - 1)):
    print(tree[i], tree[i + 1], tree[i + 2])
    if tree[i + K - 1] - tree[i] < diff:
        diff = tree[i + K - 1] - tree[i]
print(diff)

N, K = map(int, input().split())
tree = [int(input()) for n in range(N)]
diff = 10 ** 9
tree.sort()
for i in range(N - (K - 1)):
    if tree[i] == tree[i + 1] == tree[i + 2]:
        diff = 0
        break
    elif tree[i + K - 1] - tree[i] < diff:
        diff = tree[i + K - 1] - tree[i]
print(diff)


Verdicts: Runtime Error

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

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

h.sort()
m = sum(h)

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


#AtCoder

N, K = (int(x) for x in input().split())
S = (int(input()) for _ in range(N))

lst = list(S)

print(max(lst)-min)

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

h.sort()
m = sum(h)

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


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):
import sys
import numpy as np

# import os
# path = os.getcwd()
# path = os.path.join(path,"input.txt")


input = sys.stdin.readline
N,K = map(int,input().split())
h = [int(input()) for _ in range(N)]
h.sort()
print(h)
ans = float("inf")
for i in range(N-K+1):
    ans = min(ans,h[i+K-1]-h[i])
print(ans)

import sys
import numpy as np

# import os
# path = os.getcwd()
# path = os.path.join(path,"input.txt")


input = sys.stdin.readline
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: 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 func(L):
    return sum([L[i+1] - L[i] for i in range(len(L)-1)])


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

H = []

for n in range(N):
    H.append(int(input()))

H.sort()

print(min(H)) 


def func(L):
    return sum([L[i+1] - L[i] for i in range(len(L)-1)])


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

H = []

for n in range(N):
    H.append(int(input()))

H.sort()

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

print(0)


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

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

H.sort()

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

print(min(R))


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


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


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


Verdicts: Runtime Error

Runtime Error

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

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

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

print(ans)

# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


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

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(" "))
treehight = []
difference = []
for i in range(N):
    treehight.append(int(input()))
treehight.sort()
for j in range(N - 1):
    difference.append(treehight[j+1]-treehight[j])

print(min(difference))


N, K = map(int, input().split(" "))
treehight = []
difference = []
for i in range(N):
    treehight.append(int(input()))
treehight.sort()
for j in range(N - K + 1):
    difference.append(treehight[j+K-1]-treehight[j])

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,k=map(int,input().split())
hList=[]
for i in range(n):
  hList.append(int(input()))
hList.sort()
//print(hList)
ans=100000000000000
for i in range(n-k+1):
  tmp=hList[i+k-1]-hList[i]
  if(ans>tmp):
    ans=tmp
print(ans)

n,k=map(int,input().split())
hList=[]
for i in range(n):
  hList.append(int(input()))
hList.sort()
//print(hList)
ans=100000000000000
for i in range(n-k+1):
  tmp=hList[i+k-1]-hList[i]
  if(ans>tmp):
    ans=tmp
print(ans)


n,k=map(int,input().split())
hList=[]
for i in range(n):
  hList.append(int(input()))
hList.sort()
#print(hList)
ans=100000000000000
for i in range(n-k+1):
  tmp=hList[i+k-1]-hList[i]
  if(ans>tmp):
    ans=tmp
print(ans)


Verdicts: Runtime Error

Runtime Error

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

Submission attempts (in order):
N,K=map(int,input().split())
L=[]
for i in range(N) :
  L.append(int(input()))
M=[]
for x,y in zip(L,L[K-1:]) :
  M.append(y-x)
print(min(M))

N,K=map(int,input().split())
L=[]
for i in range(N) :
  L.append(int(input()))
L.sort()
M=[]
for x,y in zip(L,L[K-1:]) :
  M.append(y-x)
print(min(M))

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

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



def eva(L):
    h_l = min(L)
    h_h = max(L)
    return h_h -h_l

candidate = []
result = eva(P[:3])

def dfs(now_l,k,l):
    global result
    print(now_l)
    if len(now_l)== k :
        f = eva(now_l)
        if f < result :
            result = f
        return 
    for i in range(len(l)) :
        dfs(now_l+[l[i]], k,l[i+1:])
        if len(now_l) == k-1 :
            break
    return 

if any([i>= K for i in collections.Counter(P).values()]) :
    print(0)
else :
    dfs([],K, P) 
    print(result)

N,K = map(int,input().split())
h = [int(input()) for _ in range(N)]
h = sorted(h)
r = 10**10

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

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

tree = [int(input()) for i in range(n)]
tree.sort()

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

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

tree = [int(input()) for i in range(n)]
tree.sort()

res = (tree(i+k-1) - tree(i) for i range(n-k+11)
print(min(res))

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

tree = [int(input()) for i in range(n)]
tree.sort()

res = (tree(i+k-1) - tree(i) for i in range(n-k+1))
print(min(res))

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

tree = [int(input()) for i in range(n)]
tree.sort()

res = (tree(i+k-1) - tree(i) for i range(n-k+1))
print(min(res))

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

tree = [int(input()) for i in range(n)]
tree.sort()

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

Verdicts: Runtime Error

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):
def main():
    N, K = (int(i) for i in input().split())
    H = [int(i) for i in input().split()]
    H.sort()
    ans = 10**12
    for i in range(N-K+1):
        ans = min(ans, H[i+K-1] - H[i])

    print(ans)


if __name__ == '__main__':
    main()


def main():
    N, K = (int(i) for i in input().split())
    H = [int(input()) for i in range(N)]
    H.sort()
    ans = 10**12
    for i in range(N-K+1):
        ans = min(ans, H[i+K-1] - H[i])

    print(ans)


if __name__ == '__main__':
    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())2h=[int(input())foriinrange(N)]3h.sort()4print(min(h[i+K-1]-h[i]foriinrange(N-K+1)))

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

Verdicts: 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(reverse=True)
print(h)
dh_max = h[0]

for i in range(N - K + 1):
    dh = max(h[i:K+i]) - min(h[i:K+i])
    if dh < dh_max:
        dh_max = dh

print(dh_max)

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

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

h.sort(reverse=True)

dh_max = h[0]

for i in range(N - K + 1):
    dh = h[i] - h[K+i-1]
    if dh < dh_max:
        dh_max = dh

print(dh_max)

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-*-
import sys
input=sys.stdin.readline

def ngram(numbers,n):
    return list([numbers[i:i+n] for i in range(len(numbers)-2)])

def main():
    numbers=[]
    s_numbers=[]
    dp=[]
    n,m = map(int,input().split())
    [numbers.append(int(input())) for _ in range(n)]
    s_numbers=sorted(numbers)
    n_list=ngram(s_numbers,3)
    print(n_list)

    for data in n_list:
        if len(data)==3:
            min_data=min(data)
            max_data=max(data)
            dp.append(max_data-min_data)
        else:
            break
    print(min(dp))

if __name__=="__main__":
    main()

#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np

def main():
    numbers=[]
    n,m = map(int,input().split())
    [numbers.append(int(input())) for _ in range(n)]
    n_numbers=np.array(numbers,dtype=int)
    n_numbers.sort()
    print(min(n_numbers[i+m-1] - n_numbers[i] for i in range(n-m+1)))

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):
def christmas_eve(N: int, K: int, H: list) -> int:
    sorted_H = sorted(H, reverse=True)
    return sorted_H[0] - sorted_H[K-1]


if __name__ == "__main__":
    N, K = [int(s) for s in input().split()]
    H = [int(input()) for _ in range(N)]
    ans = christmas_eve(N, K, H)
    print(ans)


def christmas_eve(N: int, K: int, H: list) -> int:
    sorted_H = sorted(H, reverse=True)
    return min(sorted_H[i] - sorted_H[i + K - 1] for i in range(N - K + 1))


if __name__ == "__main__":
    N, K = [int(s) for s in input().split()]
    H = [int(input()) for _ in range(N)]
    ans = christmas_eve(N, K, H)
    print(ans)


Verdicts: Wrong Answer

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

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

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

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

h.sort(reverse=True)

m=int(h[0])-int(h[K-1])
print(m)

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

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

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

H.sort()

print(H)

ans=H[n-1]-H[0]

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

print(ans)


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

H.sort()

#print(H)

ans=H[n-1]-H[0]

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

print(ans)


Verdicts: Wrong Answer

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)
h = h[:K]
# print(h)
print(max(h) - min(h))



N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h = sorted(h, reverse=True)
h = h[:K]
print(h)
print(max(h) - min(h))



import numpy as np

N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h = np.array(sorted(h))
diff_h = np.zeros(N, dtype=np.int16)
diff_h[1:] = np.diff(h)
print(h)
print(diff_h)
cum_diff_h = np.cumsum(diff_h)
print(cum_diff_h)
s = cum_diff_h[K - 1 :] - cum_diff_h[: -K + 1]
print(min(s))

import numpy as np

N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h = np.array(sorted(h))
diff_h = np.zeros(N, dtype=np.int32)
diff_h[1:] = np.diff(h)
# print(h)
# print(diff_h)
cum_diff_h = np.cumsum(diff_h)
# print(cum_diff_h)
s = cum_diff_h[K - 1 :] - cum_diff_h[: -K + 1]
# print(s)
print(min(s))

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

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

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

minimum=10**10
tmp=N-K
for i in range(N-K+1):
	#print("i/minimun",i,minimum)
	if h[i+K-1]-h[i] < minimum:
		minimum=h[i+K-1]-h[i]

#print(minimum)
#print(h)

import sys

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

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

minimum=10**10
tmp=N-K
for i in range(N-K+1):
	#print("i/minimun,h[i+K-1],h[i]",i,minimum,h[i+K-1],h[i])
	if h[i+K-1]-h[i] < minimum:
		minimum=h[i+K-1]-h[i]

print(minimum)
#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):
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
ans=[]
for i in range(len(h)-K+1):
  b=h[K+1-i]-h[i]
  ans.append(b)
print(min(b))

N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
ans=[]
for i in range(len(h)-K+1):
  b=h[K+i-1]-h[i]
  ans.append(b)
print(min(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())
lis = []
for _ in range(n):
  lis.append(int(input()))
ans = 100000000000000
for i in range(n-k+1):
  s = lis[i+k-1]-lis[i]
  if s < ans:
    ans = s
print(ans)

n, k = map(int,input().split())
lis = []
for _ in range(n):
  lis.append(int(input()))
ans = 100000000000000
lis.sort()
for i in range(n-k+1):
  s = lis[i+k-1]-lis[i]
  if s < ans:
    ans = s
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()
Min = h[K] - h[0]
for i in range(N-K+1):
  if h[K+i] - h[i+1] < Min:
    Min = h[K+i] - h[K]
    
print(Min)

N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()
Min = h[K] - h[0]
for i in range(N-K+1):
  if h[K+i-1] - h[i] < Min:
    Min = h[K+i-1] - h[i]
    
print(Min)

Verdicts: Runtime Error

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

Submission attempts (in order):
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N, K = [int(x) for x in input().split()]
height = []
for _ in range(N):
    height.append(int(input()))

height.sort()
height.reverse()
sublist = []
for i in range(N-K+1):
    hmax-hmin = height[i]-height[i+K-1]
    sublist.append(hmax-hmin)

print(min(sublist))


#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N, K = [int(x) for x in input().split()]
height = []
for _ in range(N):
    height.append(int(input()))

height.sort()
height.reverse()
sublist = []
for i in range(N-K+1):
    hmaxhmin = height[i]-height[i+K]
    sublist.append(hmaxhmin)

print(min(sublist))


#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N, K = [int(x) for x in input().split()]
height = []
for _ in range(N):
    height.append(int(input()))

height.sort()
height.reverse()
sublist = []
for i in range(N-K+1):
    hmaxhmin = height[i]-heght[i+K]
    sublist.append(hmaxhmin)

print(min(sublist))



#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N, K = [int(x) for x in input().split()]
height = []
for _ in range(N):
    height.append(int(input()))

height.sort()
height.reverse()
sublist = []
for i in range(N-K+1):
    hmax-hmin = height[i]-heght[i+K]
    sublist.append(hmax-hmin)

print(min(sublist))


#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N, K = [int(x) for x in input().split()]
height = []
for _ in range(N):
    height.append(int(input()))

height.sort()
height.reverse()
sublist = []
for i in range(N-K+1):
    hmaxhmin = height[i]-height[i+K-1]
    sublist.append(hmaxhmin)

print(min(sublist))


Verdicts: Runtime Error

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):
from operator import sub

n, k = map(int, input().split())
hhh = sorted(int(input()) for _ in range(n))
print(min(map(sub, zip(hhh[k - 1:], hhh))))


from itertools import starmap
from operator import sub

n, k = map(int, input().split())
hhh = sorted(int(input()) for _ in range(n))
print(min(starmap(sub, zip(hhh[k - 1:], hhh))))


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 = 100007
print(H)
for i in range(0,len(H)-K+1):
	
	if ans >= H[i+K-1] - H[i]:
		ans =  H[i+K-1] - H[i]
		# print(ans)
print(ans)



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

H.sort()
ans = H[N-1]
# print(H)
for i in range(0,len(H)-K+1):
	
	if ans >  H[i+K-1] - H[i]:
		ans =  H[i+K-1] - H[i]
		# print(ans)
print(ans)



Verdicts: Wrong Answer

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

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

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

Verdicts: Wrong Answer

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

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

heights.sort()


answer = max(heights) - min(heights)

for i in range(0, n-k+1):
    x = heights[i:i + k]
    print(x)
    candidate = max(x) - min(x)
    if candidate < answer:
        answer = candidate

print(answer)

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


heights.sort()
ordered = heights[0:k-1]
item = max(ordered) - min(ordered)


heights.sort(reverse=True)
ordered = ordered = heights[0:k-1]
item2 = max(ordered) - min(ordered)

if item > item2:
  print(item2)
print(item)

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

heights.sort()


answer = max(heights) - min(heights)

for i in range(0, n-k+1):
    candidate = heights[i+k-1] - heights[i]
    if candidate < answer:
        answer = candidate

print(answer)

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=[int(input()) for i in range(n)]
a.sort()
x=10**9
for i in range(n-k+1):
  x=min(x,a[i+k-1]-a[k])
print(x)

n,k=map(int,input().split())
a=[int(input()) for i in range(n)]
a.sort()
x=10**9
for i in range(n-k+1):
  x=min(x,a[i+k-1]-a[i])
print(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, k = map(int, input().split())
h = list(map(int, [input() for i in range(n)]))
h.sort()
res = 10**10
for i in range(k-1, n):
    res = min(res, h[i]-[i-k+1])
print(res)

n, k = map(int, input().split())
h = list(map(int, [input() for i in range(n)]))
h.sort()
res = 10**10
for i in range(k-1, n):
    res = min(res, h[i]-h[i-k+1])
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):
h = []
for i in range(N) : 
    s = input()
    h.append(int(s))
    
h = sorted(h)
minDiff = h[len(h) - 1] - h[0]
for i in range(N) : 
    try : 
        diff = h[len(h) - K + i] - h[i]
        print(f"diff={h[len(h) - K + i]} - {h[i]} = {diff}")
        minDiff = min(minDiff , diff)
        
    except : 
        if i == 0 : minDiff = 0
        continue
print(minDiff)

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

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

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

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

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

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):
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K, *H = map(int, read().split())
H.sort()
print(min(H[i+K-1]-H[i]) for i in range(N-K+1))


import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K, *H = map(int, read().split())
H.sort()
print(min(H[i+K-1]-H[i] for i in range(N-K+1)))


Verdicts: Wrong Answer

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

Submission attempts (in order):
n,k = map(int,input().split())
h=[int(input()) for i in range(n)]
h=sort(h)
mi=float('inf')
 
for i in range(n-k+1):
    mi = min(mi, h[i+k-1]-h[i])
 
print(mi)

n,k = map(int,input().split())
h=sorted(list(int(input()) for i in range(n)))
h+=h
mi=float('inf')
ansma=0
ansmi=0
a=0
for i in range(n):
    tmpma=h[i+k]
    tmpmi=h[i]
    if n <= i:
        break
    if mi > tmpma - tmpmi:
        a=i
        mi=tmpma-tmpmi

print(h[a]-h[a+k])

n,k = map(int,input().split())
h=[int(input()) for i in range(n)]
h=sorted(h)
mi=float('inf')
 
for i in range(n-k+1):
    mi = min(mi, h[i+k-1]-h[i])
 
print(mi)


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):
a=list(map(int,input().split()))
b=list(sorted([int(input()) for i in range(a[0])]))
ans=[]
for i in range(a[0]-a[1]+1):
  ans+=[abs(b[a[1]-1]-b[i])]
print(min(ans))

a=list(map(int,input.split()))
lis=[]
for i in range(a[0]):
  lis+=int(input())
lis=lis.sort()
print(lis)

a=list(map(int,input().split()))
b=list(sorted([int(input()) for i in range(a[0])]))
ans=[]
for i in range(a[0]-a[1]+1):
  ans+=[abs(b[a[1]-1+i]-b[i])]
print(min(ans))

Verdicts: Wrong Answer

Runtime Error

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

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

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

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

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

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

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

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())
h = []
for i in range(N):
  h.append(int(input()))
h.sort()
mini = 1e9
for i in range(N-K+1):
  sub = h[i+K-1] - h[i]
  if(sub < mini){
    mini = sub
print(mini)

N, K = map(int, input().split())
h = []
for i in range(N):
  h.append(int(input()))
h.sort()
mini = 1e9
for i in range(N-K+1):
  sub = h[i+K-1] - h[i]
  if(sub < mini){
    mini = sub
print(mini)


N, K = map(int, input().split())
h = []
for i in range(N):
  h.append(int(input()))
h.sort()
mini = 1e9
for i in range(N-K+1):
  sub = h[i+K-1] - h[i]
  if(sub < mini):
    mini = sub
print(mini)


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())
hn = []
for i in range(N):
  hn.append(int(input()))
hn = sorted(hn,reverse=True)
min = 99999999
for i in range(N-K+1):
  print("hn[i] is {} , hn[K+i] is {}".format(hn[i],hn[K+i-1]))
  if min > (hn[i]-hn[K+i-1]):
    min = hn[i]-hn[K+i-1]
print(min)



N, K = map(int,input().split())
M = [int(input()) for i in range(N)]
M.sort()
lis = [0]*(N-K+1)
for i in range(N-K+1):
    lis[i] = abs(M[i]-M[i+K-1])
print(min(lis))


Verdicts: Wrong Answer

Accepted