input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
n = int(eval(input())) def make_divisors(n): lower_divisors, upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] def is_favorite(n, m): if x == 0: return False else: return n // m == n % m li = make_divisors(n) li = [x - 1 for x in li] ans = 0 for x in li: if is_favorite(n, x): ans += x print(ans)
n = int(eval(input())) def make_divisors(n): lower_divisors, upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] # 約数から1引いたものが候補 arr = make_divisors(n) arr = [x - 1 for x in arr if x >= 2] # 商と剰余が不一致ならbreakできる ans = 0 for x in arr[::-1]: if n // x != n % x: break ans += x print(ans)
p03050
from sys import stdin import math import fractions from collections import deque INF = 10 ** 10 N = int(stdin.readline().rstrip()) ans = 0 for k in range(1, int(math.sqrt(N+1))): if N % k == 0: # N = k(m+1) で表すことができる ...よってkはNの約数 # m = N/k-1 ans += ((N//k)-1) print(ans)
from sys import stdin import math import fractions from collections import deque INF = 10 ** 10 N = int(stdin.readline().rstrip()) ans = 0 for k in range(1, int(math.sqrt(N+1))): if N % k == 0: # N = k(m+1) で表すことができる ...よってkはNの約数で、N^0.5以下のもの # m = N/k-1 ans += ((N//k)-1) print(ans)
p03050
from math import floor N = int(eval(input())) ans = 0 sup = floor(pow(N,1/2)) for r in range(1,sup+1): if N % r == 0: m = N // r - 1 if 0 <= r <= m-1: ans += m print(ans)
from math import floor def divisor(n): left = [1] right = [n] sup = floor(pow(n,1/2)) for p in range(2,sup+1): if n % p == 0: left.append(p) right.append(n//p) res = left + right[::-1] return res N = int(eval(input())) div = divisor(N) ans = 0 for d in div: if d != 1 and N // (d-1) == N % (d-1): ans += (d-1) print(ans)
p03050
n, l = list(map(int, input().split())) apple = [] diff = 1001001001 minus = False for i in range(1, n+1): apple.append(l+i-1) if abs(l+i-1) < diff: diff = abs(l+i-1) if l+i-1 < 0: minus = True else: minus = False if minus: print((sum(apple) + diff)) else: print((sum(apple) - diff))
n, l = list(map(int, input().split())) apple = [] for i in range(1, n+1): apple.append(l+i-1) eat = sorted(apple, key=lambda x: abs(x)) print((sum(apple)-eat[0]))
p02994
n,l = list(map(int,input().split())) n_l = [] for i in range(n): n_l.append(i+l) min_i = 100000 for i in n_l: if abs(i) < abs(min_i): min_i = i print((sum(n_l) - min_i))
n,l = list(map(int,input().split())) r = [l+i for i in range(n)] min_r = 1000000000 for i in r: if min_r > abs(i): min_r = abs(i) ans = i print((sum(r)-ans))
p02994
n, l = list(map(int, input().split())) sa = 1000 sum = 0 for i in range(1,n+1): if sa != min(abs(l+i-1), sa): sa = min(abs(l+i-1), sa) app = l+i-1 sum += l+i-1 print((sum-app))
n,l=list(map(int,input().split())) ans=0 min_a=10**9 for i in range(n): ans+=l+i if abs(min_a)>abs(l+i): min_a=l+i print((ans-min_a))
p02994
N, L = list(map(int, input().split())) a = [] b = [] #ringo goto aji dasu for i in range(N): a.append(L+ i+1 -1) if max(a) < 0: print((sum(a)-max(a))) elif max(a) >= 0 and min(a) <= 0: print((sum(a))) else: print((sum(a)-min(a)))
N, L = list(map(int, input().split())) a = [] for i in range(N): a.append(L+i+1-1) if min(a) > 0: print((sum(a)-min(a))) elif min(a)<=0 and max(a)>=0: print((sum(a))) else: print((sum(a)-max(a)))
p02994
import heapq n, l = list(map(int, input().split())) taste = list(range(l, n + l)) ans = 0 if taste.count(0) == 1: ans = sum(taste) elif max(taste) < 0: taste = list([x * (-1) for x in taste]) heapq.heapify(taste) heapq.heappop(taste) ans = sum(taste) * (-1) else: heapq.heapify(taste) heapq.heappop(taste) ans = sum(taste) print(ans)
n, l = list(map(int, input().split())) taste = list(range(l, n + l)) ans = 0 if taste.count(0) == 1: ans = sum(taste) elif max(taste) < 0: taste.remove(max(taste)) ans = sum(taste) else: taste.remove(min(taste)) ans = sum(taste) print(ans)
p02994
N, L = list(map(int, input().split())) APsum=0 AJIList=[] AbsList=[] for i in range(N): APsum += i+L AJIList.append(i+L) AbsList.append(abs(i+L)) #print(AJIList) #print(AbsList) del AJIList[AbsList.index(min(AbsList))] print((sum(AJIList)))
N,L=list(map(int, input().split())) List=[] i=1 while i<=N: List.append(L+i-1) i+=1 MIN=abs(List[0]) HIKU=List[0] j=1 while j<N: if abs(List[j])<MIN: HIKU=List[j] MIN=abs(List[j]) j+=1 del List[List.index(HIKU)] print((sum(List)))
p02994
n,l=list(map(int,input().split())) import copy apple_l=[] pie=0 deli=[] for i in range(1,n+1): pie+=l+i-1 deli.append(l+i-1) ans={} ans2=[] for j in range(1,n+1): deli2=copy.copy(deli) deli2.remove(l+j-1) ans[abs(sum(deli2)-pie)]=sum(deli2) ans2.append(abs(sum(deli2)-pie)) print((ans[min(ans2)]))
n,l=list(map(int,input().split())) mngap=[1,abs(l+1-1)] for i in range(2,n+1): if mngap[1]>abs(l+i-1): mngap=[i,abs(l+i-1)] total=0 for i in range(1,n+1): total+=l+i-1 print((total-(l+mngap[0]-1)))
p02994
N, L = list(map(int, input().split())) l = [L + i for i in range(N)] l.sort(key=lambda x: abs(x)) ans = sum(l[1:]) print(ans)
N, L = list(map(int, input().split())) n = [] for i in range(1, N+1): n.append(L+i-1) a = 200 I = "" for i in range(N): if abs(n[i]) < a: a = abs(n[i]) I = i print((sum(n) - n[I]))
p02994
n,l = list(map(int,input().split())) p1 = [(l+i-1) for i in range(1,n+1)] p2 = [i**2 for i in p1] num = p2.index(min(p2)) sums = sum(p1)-p1[num] print(sums)
n,l = list(map(int,input().split())) mn = 1000 for i in range(1,n+1): ans = l+i-1 if abs(ans)<abs(mn): ans1 = ans mn = min(abs(mn),abs(ans)) ans2 = 0 for j in range(1,n+1): ans2 += (l+j-1) print((ans2-ans1))
p02994
n,l = list(map(int,input().split())) mn = 1000 for i in range(1,n+1): ans = l+i-1 if abs(ans)<abs(mn): ans1 = ans mn = min(abs(mn),abs(ans)) ans2 = 0 for j in range(1,n+1): ans2 += (l+j-1) print((ans2-ans1))
n,l = list(map(int,input().split())) mn = 1000 sums = 0 for i in range(n): taste = l+i sums += taste for i in range(n): taste = l+i if mn > abs(taste): ans = taste mn = abs(taste) print((sums-ans))
p02994
N, L = list(map(int, input().split())) s = N*(2*L+N-1) // 2 l = [abs(L+i) for i in range(N)] print((s - (L+l.index(min(l)))))
N, L = list(map(int, input().split())) # 元々の味(等差数列の和の公式より) s = N*(2*L+N-1) // 2 # 味の差の絶対値=リンゴiの味の絶対値 l = [abs(L+i) for i in range(N)] # 味の絶対値が最小になるリンゴのindexを求め、sからその味を引けばよい print((s - (L+l.index(min(l)))))
p02994
N, L = list(map(int, input().split())) # 元々の味(等差数列の和の公式より) s = N*(2*L+N-1) // 2 # 味の差の絶対値=リンゴiの味の絶対値 l = [abs(L+i) for i in range(N)] # 味の絶対値が最小になるリンゴのindexを求め、sからその味を引けばよい print((s - (L+l.index(min(l)))))
N, L = list(map(int, input().split())) # 元々の味(等差数列の和の公式より) s = N*(2*L+N-1) // 2 # 味の絶対値が最小になるリンゴの味を求める if L+N-1 < 0: eat = L+N-1 elif L > 0: eat = L else: eat = 0 # 食べる(最適なリンゴ)以外の味の和 print((s - eat))
p02994
n, l = list(map(int,input().split())) pies = [l+i-1 for i in range(1,n+1)] pie_plan = sum(pies) pie_real = 0 diff_plan_real = float("inf") for i in range(1,n+1): pie_provisonal = sum([l+j-1 for j in range(1,n+1) if j != i]) if abs(pie_plan - pie_provisonal) < diff_plan_real: diff_plan_real = abs(pie_plan - pie_provisonal) pie_real = pie_provisonal print(pie_real)
def main(): N, L = (int(i) for i in input().split()) s = 0 li = [] for i in range(1, N+1): s += L + i - 1 li.append((abs(L + i - 1), i)) li.sort() print((s - (L + li[0][1] - 1))) if __name__ == '__main__': main()
p02994
n, l = list(map(int, input().split())) taste = [l+i for i in range(n)] ans = [abs(i) for i in taste] del taste[ans.index(min(ans))] print((sum(taste)))
n, l = list(map(int, input().split())) taste = [l+i for i in range(n)] taste.sort(key=lambda x: abs(x)) print((sum(taste[1:])))
p02994
N, L = list(map(int,input().split())) a = L - 1 b = [a + i for i in range(1, N+1)] s = sum(b) if 0 in b: print(s) elif s > 0: print((s - min(b))) else: print((s - max(b)))
N, L = list(map(int,input().split())) b = [L -1 + i for i in range(1, N+1)] s = sum(b) if 0 in b: print(s) elif s > 0: print((s - min(b))) else: print((s - max(b)))
p02994
n, l = list(map(int, input().split())) apples = list(range(l, l + n)) if 0 in apples: print((sum(apples))) elif l < 0: print((sum(apples) - max(apples))) else: print((sum(apples) - min(apples)))
n, l = list(map(int, input().split())) apples = list(range(l, l + n)) print((sum(apples) - min(apples, key=abs)))
p02994
""" author : halo2halo date : 9, Jan, 2020 """ import sys # import numpy as np import itertools read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) N, L = list(map(int, readline().split())) F = [L + i for i in range(N)] tmp = 1000 ans=0 for i in itertools.combinations(F, N - 1): if abs(sum(F)-sum(i)) < tmp: tmp = abs(sum(F)-sum(i)) ans=sum(i) print(ans)
""" author : halo2halo date : 9, Jan, 2020 """ import sys # import numpy as np import itertools read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) N, L = list(map(int, readline().split())) F = [L + i for i in range(N)] F.sort(key=lambda x: abs(x)) print((sum(F[1:])))
p02994
n,l=list(map(int,input().split())) ll=[] lll=[] mi=False for i in range(1,n+1): ll.append(l+i-1) lll.append(abs(l+i-1)) if (l+i-1)<0: mi=True if 0 in ll: print((sum(ll))) elif mi: print((sum(ll)+min(lll))) else: print((sum(ll)-min(ll)))
n,l=list(map(int,input().split())) a=[l+i for i in range(n)] l=[abs(l+i) for i in range(n)] l.sort() x=l[0] s=sum(a) if x in a: print((s-x)) else: print((s+x))
p02994
N , L = list(map(int,input().split())) taste = [0] * N for i in range(1,N+1) : taste[i-1] = L + i - 1 taste.sort(key=lambda i : abs(i)) ans = sum(taste[1:N]) print(ans)
N, L = list(map(int, input().split())) A = [L + i for i in range(N)] A.sort(key=lambda a: abs(a)) print((sum(A) - A[0]))
p02994
n,l=list(map(int,input().split())) pi=0 a=[] abs_a=[] for i in range(1,n+1): pi+=l+i-1 for i in range(1,n+1): a.append(l+i-1) for i in range(n): abs_a.append(abs(a[i])) if max(a)<0: p=pi+min(abs_a) else: p=pi-min(abs_a) print(p)
n,l=list(map(int,input().split())) pi=0 a=[] abs_a=[] for i in range(1,n+1): pi+=l+i-1 a.append(l+i-1) for i in range(n): abs_a.append(abs(a[i])) if max(a)<0: p=pi+min(abs_a) else: p=pi-min(abs_a) print(p)
p02994
N,L = list(map(int,input().split())) lis_taste = [L + (i + 1) - 1 for i in range(N)] lis_abs = [abs(i) for i in lis_taste] lis_taste.pop(lis_abs.index(min(lis_abs))) print((sum(lis_taste)))
n,l=list(map(int,input().split())) a=list([l+x-1 for x in list(range(1,n+1))]) a_abs=list([abs(x) for x in a]) print((sum(a)-a[a_abs.index(min(list([abs(x) for x in a])))]))
p02994
N,L=list(map(int,input().split())) taste=[L+i for i in range(N)] print((sum(taste)-min(taste,key=abs)))
N,L=list(map(int,input().split())) taste=list(range(L,L+N)) print((sum(taste)-min(taste,key=abs)))
p02994
n, l = list(map(int, input().split())) nt = 0 nt1 = 0 for i in range(n): nt += l + i if l >= 0: nt1 = nt - l elif l + n -1 <=0: nt1 = nt -(l + n -1) else: nt1 = nt print(nt1)
n, l = list(map(int, input().split())) eat = 0 nt = 0 if l >= 0: eat = l elif l + n-1 <= 0: eat = l + n -1 else: eat = 0 for i in range(n): nt += l + i print((nt- eat))
p02994
N, L = list(map(int, input().split())) total = 0 for i in range(N): total += (L + i) if L > 0: print((total - L)) elif L + N - 1 < 0: print((total - (L + N - 1))) else: print(total)
import sys def solve(): input = sys.stdin.readline N, L = list(map(int, input().split())) sumT, minT = 0, 100000000000 pm = 0 for i in range(N): sumT += L + i if abs(L + i) < minT: minT = abs(L + i) if L + i < 0: pm = 1 print((sumT - minT * (-1) ** pm)) return 0 if __name__ == "__main__": solve()
p02994
import copy N, L = list(map(int, input().split())) apple_taste = [L+i for i in range(N)] pie_taste = sum(apple_taste) min_diff = 100000 for i in range(N): ap = copy.deepcopy(apple_taste) ap[i] = 0 pie_taste2 = sum(ap) diff = abs(pie_taste - pie_taste2) if diff < min_diff: min_diff = diff min_index = i apple_taste[min_index] = 0 print((sum(apple_taste)))
N, L = list(map(int, input().split())) pie = 0 min_abs = 10000 min_abs_apple = None for i in range(N): if min_abs > abs(i + L): min_abs = abs(i + L) min_abs_apple = i + L pie += i + L print((pie - min_abs_apple))
p02994
n,l = list(map(int,input().split())) all_eat = 0 abs_min = float("inf") for i in range(n): all_eat += l + i if abs(l + i) < abs(abs_min): abs_min = l + i print((all_eat - abs_min))
n,l = list(map(int,input().split())) k = (l + (l + n - 1)) * n // 2 a = float("inf") v = 0 for i in range(l, l+n): if a > abs(i): v = i a = abs(i) print((k - v))
p02994
n,l = list(map(int,input().split())) id = 0 ans = 0 for i in range(n): ans+=l+i if abs(l+id)>abs(l+i): id = i print((ans-l-id))
def solve(): n,l = list(map(int,input().split())) mn = 10**10 s = 0 for i in range(n): s+=l+i if abs(mn)>abs(l+i): mn = l+i print((s-mn)) if __name__=='__main__': solve()
p02994
n, l = list(map(int, input().split())) a = [0]*n b = [0]*n for i in range(n): a[i] = l+i for i in range(n): b[i] = abs(sum(a) - (sum(a) - a[i])) remove = a[b.index(min(b))] print((int(sum(a)-remove)))
n, l = list(map(int, input().split())) a = [0]*n b = [0]*n for i in range(n): a[i] = l+i for i in range(n): b[i] = abs(a[i]) remove = a[b.index(min(b))] print((int(sum(a)-remove)))
p02994
import sys # input = sys.stdin.readline N, L = list(map(int, input().split())) Lsum = sum([L + i for i in range(N)]) for i in range(N): if L + i == 0: ans = i break else: if L + N - 2 < 0: ans = N - 1 else: ans = 0 print((Lsum - (L + ans)))
N, L = list(map(int, input().split())) apples = [L + i - 1 for i in range(1, N + 1)] apples.sort(key=lambda x: abs(x)) print((sum(apples) - apples[0]))
p02994
n,l=list(map(int,input().split())) t=a=0 m=1e9 for i in range(n): if abs(l+i)<m: m=abs(l+i) t=l+i a+=l+i print((a-t))
n,l=list(map(int,input().split()));print((sum(sorted(list(range(l,l+n)),key=abs)[1:])))
p02994
N, L = [int(i) for i in input().split(' ')] min_ = L max_ = L + N -1 def eat_apple(N, L): if L < 0: if max_<0: return max_ return 0 return L print((int((min_+max_)*(max_-min_+1)/2 - eat_apple(N, L))))
N, L = [int(i) for i in input().split()] min_ = L max_ = L + N -1 def eat_apple(N, L): if max_<0: return max_ if L < 0: return 0 return L print(((min_+max_)*(max_-min_+1)//2 - eat_apple(N, L)))
p02994
N, L = [int(i) for i in input().split()] min_ = L max_ = L + N -1 def eat_apple(): if max_<0: return max_ if L < 0: return 0 return L print(((min_+max_)*(max_-min_+1)//2 - eat_apple()))
N, L = [int(i) for i in input().split()] min_ = L max_ = L + N -1 def eat_apple(N, L, max_): if max_<0: return max_ if L < 0: return 0 return L print(((min_+max_)*(max_-min_+1)//2 - eat_apple(N, L, max_)))
p02994
N,L = list(map(int,input().split())) A = [L+i for i in range(N)] x = 10**9 y = -1 for a in A: if abs(a) < x: x = abs(a) y = a print((sum(A) - y))
N,L = list(map(int,input().split())) R = L+N-1 if L <= 0 <= R: print((sum(range(L,R+1)))) elif L > 0: print((sum(range(L+1,R+1)))) else: print((sum(range(L,R))))
p02994
import bisect n,l = list(map(int,input().split())) aji = [l+i for i in range(n)] index = bisect.bisect_left(aji,0) if index == n: index -= 1 print((sum(aji) - aji[index]))
n,l = list(map(int,input().split())) ans = (l-1) * n + n * (n+1) // 2 if l + n - 1 < 0: print((ans - (l+n-1))) elif l > 0: print((ans - l)) else: print(ans)
p02994
N, L = list(map(int, input().split())) diff_min = 100 + 200 - 1 apples = list() remove_apple = 0 for i in range(N): taste = L + i apples.append(taste) if abs(taste) < diff_min: diff_min = abs(taste) remove_apple = taste print((sum(apples) - remove_apple))
n, l = list(map(int, input().split())) diff = 300 ans = [0] * n p = 0 for i in range(n): taste = l + i ans[i] = taste if diff > abs(taste): diff = abs(taste) p = i print((sum(ans) - ans[p]))
p02994
n, l = list(map(int, input().split())) if l > 0: c = l elif l + n - 1 < 0: c = l + n - 1 else: c = 0 print((l * n + n * (n - 1) // 2 - c))
n, l = list(map(int, input().split())) a, b = sorted([l, l + n - 1]) print((sum(range((a + 1 if a > 0 else a), (b - 1 if b < 0 else b) + 1))))
p02994
n,l=list(map(int,input().split())) li=[i+l for i in range(n)] l=[abs(i+l) for i in range(n)] p=l.index(min(l)) li.pop(p) print((sum(li)))
N, L = list(map(int, input().split())) L = list(range(L, N+L)) L_abs=list([abs(x) for x in L]) L.pop(L_abs.index(min(L_abs))) print((sum(L)))
p02994
N, L = [int(i) for i in input().split()] taste = [L + i - 1 for i in range(1, N + 1)] absolute = float('inf') ans = float('inf') total = sum(taste) for i in range(N): total_b = sum(taste[:i] + taste[i + 1:]) if abs(total - total_b) < absolute: ans = total_b absolute = abs(total - total_b) print(ans)
N, L = [int(i) for i in input().split()] max_taste = L + N - 1 # おいしさの絶対値が最も小さいりんごを食べ、残りでアップルパイを作る if max_taste <= 0: eat_taste = max_taste elif L >= 0: eat_taste = L else: eat_taste = 0 print(((L + max_taste) * (max_taste - L + 1) // 2 - eat_taste))
p02994
N, L = list(map(int, input().split())) t = [L + _ - 1 for _ in range(1, N+1)] # 絶対値が一番小さい要素を0に変えてsumをとりたい abseat = 299 eat = 299 for i in range(N): abst = abs(t[i]) if abst < abseat: abseat = abs(t[i]) eat = t[i] ans = sum(t) - eat print(ans)
N, L = list(map(int, input().split())) t = [L + _ - 1 for _ in range(1, N+1)] # 絶対値が一番小さい要素を0に変えてsumをとりたい t = sorted(t, key=lambda x: abs(x)) """ abseat = 299 eat = 299 for i in range(N): abst = abs(t[i]) if abst < abseat: abseat = abs(t[i]) eat = t[i] ans = sum(t) - eat """ ans = sum(t) - t[0] print(ans)
p02994
N, L = list(map(int, input().split())) ans = 0 min = L for i in range(1, N+1): a = L+i-1 ans += a if abs(a) < abs(min): min = a ans -= min print(ans)
N, L = list(map(int, input().split())) v = [L+i for i in range(N)] ans = sum(v) - min(v, key=abs) print(ans)
p02994
N, L = list(map(int, input().split())) tastes = [L + i - 1 for i in range(1, N+1)] apple_eaten = min([abs(t) for t in tastes]) if apple_eaten in tastes: print((sum(tastes) - apple_eaten)) else: print((sum(tastes) + apple_eaten))
import sys readline = sys.stdin.readline def main(): N, L = list(map(int, readline().rstrip().split())) A = [L+i-1 for i in range(1, N+1)] A_abs = [abs(a) for a in A] mi_idx = A_abs.index(min(A_abs)) print((sum(A) - A[mi_idx])) if __name__ == '__main__': main()
p02994
N, L = list(map(int, input().split())) A = [] for i in range(1, N + 1): A.append(L + i - 1) cur_diff = float('inf') ans = float('inf') Sum = sum(A) for a in A: tmp = Sum - a diff = abs(Sum - tmp) if diff < cur_diff: cur_diff = diff ans = tmp print(ans)
N, L = list(map(int, input().split())) sumA = 0 for i in range(N): sumA += (L + i) cur_diff = float('inf') ans = 0 for i in range(N): tmp = sumA - (L + i) diff = abs(sumA - tmp) if diff < cur_diff: cur_diff = diff ans = tmp print(ans)
p02994
import copy N,L = list(map(int,input().split())) flaver = [] for i in range(1,N + 1): flaver.append(L + i - 1) flaver_sum = sum(flaver) for i in range(len(flaver)): c_flaver = copy.deepcopy(flaver) del c_flaver[i] if i == 0: tmp_min = abs(flaver_sum - sum(c_flaver)) index = i if abs(flaver_sum - sum(c_flaver)) < tmp_min: tmp_min = abs(flaver_sum - sum(c_flaver)) index = i del flaver[index] print((sum(flaver)))
N, L = list(map(int, input().split())) apples = [i + L for i in range(N)] apple_pie = sum(apples) ans = float('inf') for apple in apples: if ans > abs(apple): ans = abs(apple) val = apple print((sum(apples) - val))
p02994
N, K = list(map(int, input().split())) h = [int(eval(input())) for _ in range(N)] h = sorted(h) dh = [] for i in range(N - K + 1): dh = dh + [h[i + K - 1]-h[i]] print((min(dh)))
N, K = list(map(int, input().split())) h = sorted([int(eval(input())) for _ in range(N)]) print((min([h[i+K-1]-h[i] for i in range(N - K + 1)])))
p03208
n,k = list(map(int,input().split())) h = [int(eval(input())) for _ in range(n)] h.sort() hh = [0]*(n-1) for i in range(n-1): hh[i] = h[i+1] - h[i] ans = 10**10 for i in range(n-k+1): ans = min(ans,sum(hh[i:i+k-1])) print(ans)
n,k = list(map(int,input().split())) h = [int(eval(input())) for _ in range(n)] #n,k = 7,3 #h = [10,11,12,14,15,20,0] h.sort() ans = 10**10 for i in range(n-k+1): ans = min(h[i+k-1] - h[i] , ans) print(ans)
p03208
import itertools n,k=list(map(int,input().split())) H=[int(eval(input())) for i in range(n)] Hn=list(itertools.combinations(H,k)) print((min([max(list(i))-min(list(i)) for i in Hn])))
n,k=list(map(int,input().split())) h=sorted([int(eval(input())) for i in range(n)]) print((min([h[i+k-1]-h[i] for i in range(n-k+1)])))
p03208
n,k=list(map(int,input().split())) A=[] for i in range(n): A.append(int(eval(input()))) C=[] A.sort() for i in range(n-k+1): B=[] for j in range(k): B.append(A[i+j]) C.append(max(B)-min(B)) print((min(C)))
n,k=list(map(int,input().split())) A=[] for i in range(n): A.append(int(eval(input()))) C=[] A.sort() for i in range(n-k+1): C.append(A[i+k-1]-A[i]) print((min(C)))
p03208
import sys n, k = list(map(int, input().split())) lines = sys.stdin.readlines() trees = [None] * n for i in range(n): trees[i] = int(lines[i]) trees.sort() #print(trees) min_h = sys.maxsize k_ = k-1 for i in range(n-k+1): tmp = trees[i+k_] - trees[i] if tmp < min_h: min_h = tmp print(min_h)
import sys n, k = list(map(int, input().split())) lines = sys.stdin.readlines() trees = [None] * n for i in range(n): trees[i] = int(lines[i]) trees.sort() #print(trees) min_h = sys.maxsize k_1 = k - 1 for i in range(n-k+1): height_diff = trees[i + k_1] - trees[i] if height_diff < min_h: min_h = height_diff print(min_h)
p03208
N,K=list(map(int,input().split(" "))) H=[int(eval(input())) for _ in range(N)] H.sort() tmax=10**9 for a in range(N-K+1): h1,h2=H[a],H[a+K-1] tmax=min(tmax,abs(h1-h2)) if(tmax==0): break print(tmax)
N,K=list(map(int,input().split())) H=[int(eval(input())) for _ in range(N)] H.sort() tmp=H[K-1]-H[0] for i in range(0,N-K+1): if tmp>H[K+i-1]-H[i]: tmp=H[K+i-1]-H[i] print(tmp)
p03208
from collections import deque n,k = list(map(int,input().split())) h = sorted([int(eval(input())) for _ in range(n)]) x = deque(h[:k]) mn = max(x) - min(x) for i in range(k,n): x.append(h[i]) x.popleft() mn = min(mn,max(x) - min(x)) print(mn)
from collections import deque n,k = list(map(int,input().split())) h = sorted([int(eval(input())) for _ in range(n)]) x = deque([]) mn = 10**9 for i in h: x.append(i) if len(x) >= k: mn = min(mn,x[k-1]-x[0]) x.popleft() print(mn)
p03208
from collections import deque n,k = list(map(int,input().split())) h = sorted([int(eval(input())) for _ in range(n)]) x = deque([]) mn = 10**9 for i in h: x.append(i) if len(x) >= k: mn = min(mn,x[k-1]-x[0]) x.popleft() print(mn)
n,k = list(map(int,input().split())) h = sorted([int(eval(input())) for _ in range(n)]) mn = 10**9 for i in range(n-k+1): mn = min(mn,h[i+k-1] - h[i]) print(mn)
p03208
def resolve(): n,k=list(map(int, input().split())) l=[int(eval(input())) for i in range(n)] l.sort() a=0 ans=10**9 for i in range(n-k+1): a=l[i+k-1]-l[i] ans=min(a,ans) print(ans) resolve()
def resolve(): n,k=list(map(int, input().split())) l=[int(eval(input())) for i in range(n)] l.sort() print((min(l[i+k-1]-l[i] for i in range(n-k+1)))) resolve()
p03208
def resolve(): n,k=list(map(int, input().split())) l=[int(eval(input())) for i in range(n)] l.sort() print((min(l[i+k-1]-l[i] for i in range(n-k+1)))) resolve()
import sys def input(): return sys.stdin.readline().strip() def resolve(): n,k=list(map(int, input().split())) l=[int(eval(input())) for i in range(n)] l.sort() ans=10**18 for i in range(0,n-k+1): ans=min(ans,l[i+k-1]-l[i]) print(ans) resolve()
p03208
# coding: utf-8 import itertools N, K = list(map(int, input().split())) lst = [int(eval(input())) for _ in range(N)] lst2 = list(itertools.combinations(lst, K)) lst3 = [] for l in lst2: diff = max(l)-min(l) lst3.append(diff) print((min(lst3)))
# coding: utf-8 import itertools N, K = list(map(int, input().split())) lst = sorted([int(eval(input())) for _ in range(N)], reverse=True) ans = 10000000000 for i in range(N-K+1): l = lst[i]-lst[i+K-1] if l < ans: ans = l print(ans)
p03208
# coding: utf-8 import itertools N, K = list(map(int, input().split())) lst = sorted([int(eval(input())) for _ in range(N)], reverse=True) ans = 10000000000 for i in range(N-K+1): l = lst[i]-lst[i+K-1] if l < ans: ans = l print(ans)
# coding: utf-8 N, K = list(map(int, input().split())) lst = sorted([int(eval(input())) for _ in range(N)], reverse=True) ans = 10000000000 for i in range(N-K+1): l = lst[i]-lst[i+K-1] if l < ans: ans = l print(ans)
p03208
N, K = list(map(int, input().split())) h = [None] * N for i in range(N): h[i] = int(eval(input())) h = sorted(h) sub_min = h[N-1] - h[0] for i in range(N-K+1): if h[i+K-1] - h[i] < sub_min: sub_min = h[i+K-1] - h[i] print(sub_min)
# coding: utf-8 # https://atcoder.jp/contests/abc115 def main(): N, K = list(map(int, input().split())) h = [None] * N for i in range(N): h[i] = int(eval(input())) h = sorted(h) diff = 10**10 for i in range(N-K+1): newdiff = h[i+K-1]-h[i] if newdiff < diff: diff = newdiff return diff print((main()))
p03208
import sys, copy, math, collections, itertools n, k = (int(i) for i in input().split()) hs = [int(eval(input())) for i in range(n)] hs.sort() i=0 m=-1 l=len(hs) while True: if l < (i+k): break tmp = hs[i:i+k] cnd=tmp[-1] - tmp[0] if m==-1: m=cnd else: if cnd < m: m=cnd i+=1 print((int(m)))
import sys, copy, math, collections, itertools n, k = (int(i) for i in input().split()) hs = [int(eval(input())) for i in range(n)] hs.sort() i=0 m=-1 l=len(hs) while True: if l < (i+k): break # tmp = hs[i:i+k] cnd=hs[i+k-1] - hs[i] if m==-1: m=cnd else: if cnd < m: m=cnd i+=1 print((int(m)))
p03208
import itertools,math n=input().split() n=[int(i) for i in n] h=[] for i in range(n[0]): h.append(int(eval(input()))) q=-1 for j in itertools.combinations(h,n[1]): if q>max(j)-min(j) or q==-1: q=max(j)-min(j) if q==0: break print(q)
n=input().split() n=[int(i) for i in n] h=[0]*n[0] for i in range(n[0]): h[i]=int(eval(input())) h.sort() q=-1 for i in range(0,len(h)-n[1]+1): a=h[i+n[1]-1]-h[i] if q==-1 or q>a: q=a print(q)
p03208
n,k=list(map(int,input().split())) h=[int(eval(input())) for i in range(n)] h.sort() ans=1000000000 for j in range(len(h)-2): c=h[j:j+k] ans=min(ans,c[-1]-c[0]) print(ans)
n,k=list(map(int,input().split())) h=[int(eval(input())) for i in range(n)] h.sort() print((min([x-y for (x,y) in zip(h[k-1:],h[:-k+1])])))
p03208
n,k = list(map(int, input().split())) h = [0] * n ans = 0 for i in range(n): h[i] = int(eval(input())) h.sort() for i in range(n-k+1): temp = max(h[i:i+k]) - min(h[i:i+k]) if temp == 0: ans = temp break elif i == 0: ans = temp elif ans > temp: ans = temp print(ans)
n,k = list(map(int, input().split())) h = [0] * n ans = [] for i in range(n): h[i] = int(eval(input())) h.sort() for i in range(n-k+1): ans.append(h[i+k-1] - h[i]) print((min(ans)))
p03208
# ABC115C - Christmas Eve n, k = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, [input().rstrip() for _ in range(n)]))) ans = lst[k - 1] - lst[0] for i, j in zip(lst, lst[k - 1 :]): ans = min(ans, j - i) print(ans)
# ABC115C - Christmas Eve import sys input = sys.stdin.readline n, k = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, [input().rstrip() for _ in range(n)]))) ans = lst[k - 1] - lst[0] for i, j in zip(lst, lst[k - 1 :]): ans = min(ans, j - i) print(ans)
p03208
# ABC115C - Christmas Eve def main(): n, k = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, [input().rstrip() for _ in range(n)]))) ans = lst[k - 1] - lst[0] for i, j in zip(lst, lst[k - 1 :]): ans = min(ans, j - i) print(ans) if __name__ == "__main__": main()
# ABC115C - Christmas Eve import sys input = sys.stdin.readline def main(): n, k = list(map(int, input().rstrip().split())) lst = sorted(list(map(int, [input().rstrip() for _ in range(n)]))) ans = lst[k - 1] - lst[0] for i, j in zip(lst, lst[k - 1 :]): ans = min(ans, j - i) print(ans) if __name__ == "__main__": main()
p03208
def main(): N,K=list(map(int,input().split())) h=[] for i in range(N): a=int(eval(input())) h.append(a) h.sort() result=10**10 count=0 for i in range(N-K+1): count=h[i+K-1]-h[i] result=min(result,count) print(result) if __name__=="__main__": main()
from sys import stdin def main(): #入力 readline=stdin.readline n,k=list(map(int,readline().split())) h=[0]*n for i in range(n): h[i]=int(readline()) h.sort() ans=float("inf") for i in range(k-1,n): s=h[i]-h[i-k+1] ans=min(s,ans) print(ans) if __name__=="__main__": main()
p03208
n, k = list(map(int, input().split())) hl = [int(eval(input())) for _ in range(n)] hl_s = sorted(hl, reverse=True) delta = 10*10**9 if n > 1000: while n < 1000: if hl_s[n//2] < (hl_s[0] + hl_s[n-1])//2: hl_s = hl_s[:n//2] else: hl_s = hl_s[n//2:] n = len(hl_s) for i in range(len(hl_s)-k+1): h_max = max(hl_s[i:i+k]) h_min = min(hl_s[i:i+k]) if delta > (h_max - h_min): delta = h_max - h_min if delta == 0: break print(delta)
n, k = list(map(int, input().split())) hl = [int(eval(input())) for _ in range(n)] hl.sort() h_min = min(hl[i+k-1] - hl[i] for i in range(n-k+1)) print(h_min)
p03208
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from heapq import heapify, heappop, heappush def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, K = MAP() H = [INT() for i in range(N)] H.sort() ans = INF for i in range(N-K+1): mi = H[i:i+K][0] ma = H[i:i+K][-1] tmp = ma - mi ans = min(tmp, ans) print(ans)
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from heapq import heapify, heappop, heappush def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, K = MAP() H = [INT() for i in range(N)] H.sort() ans = INF for i in range(N-K+1): mi = H[i] ma = H[i+K-1] tmp = ma - mi ans = min(tmp, ans) print(ans)
p03208
N,K=list(map(int,input().split())) h=[int(eval(input())) for i in range(N)] h.sort() mindif=h[K-1]-h[0] for i in range(N-K+1): tmp=h[i:i+K] dif=tmp[-1]-tmp[0] if mindif>dif: mindif=dif print(mindif)
N,K=list(map(int,input().split())) h=[int(eval(input())) for i in range(N)] h.sort() mindif=h[K-1]-h[0] for i in range(N-K+1): dif=h[i+K-1]-h[i] if mindif>dif: mindif=dif print(mindif)
p03208
N, K = list(map(int, input().split())) h = sorted([int(eval(input())) for i in range(N)]) res = [] for i in range(N-K+1): tmp = h[i:i+K] res.append(tmp[-1] - tmp[0]) print((min(res)))
N, K = list(map(int, input().split())) h = sorted([int(eval(input())) for i in range(N)]) res = [] for i in range(N-K+1): res.append(h[i+K-1] - h[i]) print((min(res)))
p03208
n,k=list(map(int,input().split())) h=[0]*n for i in range(n): h[i]=int(eval(input())) h.sort() ans=10**9 for i in range(n-k+1): ans= min(max(h[i:i+k])-min(h[i:i+k]), ans) print(ans)
n,k =list(map(int,input().split())) h=[0]*n for i in range(n): h[i]=int(eval(input())) h.sort() ans=10**9 for i in range(n-k+1): ans= min(h[i+k-1]-h[i], ans) print(ans)
p03208
N, K = list(map(int,input().split( ))) H =[] for i in range(N): h = int(eval(input())) H.append(h) ansl = [] H.sort() for i in range(N - K + 1): HK = H[i:i+K] ans = max(HK)-min(HK) ansl.append(ans) print((min(ansl)))
N, K = list(map(int,input().split( ))) H =[] for i in range(N): h = int(eval(input())) H.append(h) ansl = [] H.sort() for i in range(N - K + 1): #HK = H[i:i+K] #ans = max(HK)-min(HK) ans = H[i + K - 1] - H[i] ansl.append(ans) print((min(ansl)))
p03208
import itertools N, K = (int(i) for i in input().split(' ')) h=[] for i in range(N): h.append(int(eval(input()))) m = -1 for l in itertools.combinations(h,K): d = max(l) - min(l) if d < m or m == -1: m = d print(m)
N, K = (int(i) for i in input().split(' ')) h=[] for i in range(N): h.append(int(eval(input()))) h.sort() m = -1 for i in range(N-K+1): d = h[i+K-1] - h[i] if d < m or m == -1: m = d print(m)
p03208
n,k = list(map(int,input().split())) h = sorted([int(eval(input())) for _ in range(n)]) ans = h[k-1]-h[0] for i in range(n-k+1): m = h[i+k-1]-h[i] ans = min(m,ans) print(ans)
n,k = list(map(int,input().split())) h = sorted([int(eval(input())) for _ in range(n)]) print((min(h[j+k-1]-h[j] for j in range(n-k+1))))
p03208
from itertools import combinations N, K = list(map(int, input().split())) H = [int(eval(input())) for _ in range(N)] ans = 10**9 for v in combinations(H, K): diff = max(v) - min(v) if diff < ans: ans = diff print(ans)
N, K = list(map(int, input().split())) H = sorted([int(eval(input())) for _ in range(N)]) print((min(H[i+K-1] - H[i] for i in range(N-K+1))))
p03208
def mapt(fn, *args): return tuple(map(fn, *args)) def Input(): return mapt(int, input().split(" ")) def main(): n, k = Input() data = sorted(int(eval(input())) for _ in range(n)) ans = 1e9 for i in range(n-k+1): x = data[i:i+k] ans = min(ans, max(x) - min(x)) print(ans) main()
def main(): n, k = list(map(int, input().split(" "))) data = sorted(int(eval(input())) for _ in range(n)) print((min([data[i+k-1] - data[i] for i in range(n-k+1)]))) main()
p03208
import heapq mINF=-10**10 N,K=list(map(int,input().split(" "))) arr=[mINF]*N for z in range(N): heapq.heapreplace(arr,int(eval(input()))) arr2=[mINF]*K for z in range(K): heapq.heapreplace(arr2,heapq.heappop(arr)) r=max(arr2)-min(arr2) try: while True: heapq.heapreplace(arr2,heapq.heappop(arr)) rb=max(arr2)-min(arr2) if rb<r: r=rb except Exception: pass print(r)
import heapq N,K=list(map(int,input().split(" "))) arr=[0]*N for z in range(N): heapq.heapreplace(arr,int(eval(input()))) arr2=[0]*K for z in range(K): arr2[z]=heapq.heappop(arr) r=arr2[-1]-arr2[0] z=0 try: while True: arr2[z]=heapq.heappop(arr) if z==K-1: zz=0 else: zz=z+1 rb=arr2[z]-arr2[zz] if rb<r: r=rb z+=1 if z==K: z=0 except Exception: pass print(r)
p03208
n,k=list(map(int,input().split())) h=[list(map(int,input().split())) for _ in range(n)] import itertools result = 10**9 h_sorted = sorted(h) for i in range(n-k+1): k_arr = h_sorted[i:i+k] k_arr = list(itertools.chain.from_iterable(k_arr)) result = min(result, k_arr[k-1]-k_arr[0]) print(result)
n,k=list(map(int,input().split())) h=[int(eval(input())) for _ in range(n)] h.sort() result = 10**9 for i in range(n-k+1): result = min(result, h[i+k-1] - h[i]) print(result)
p03208
N, K = list(map(int, input().split())) h = [int(eval(input())) for i in range(N)] h.sort() h_new = [h[i + (K - 1)] - h[i] for i in range(0, N - (K - 1))] print((min(h_new)))
N, K = list(map(int, input().split())) h = sorted([int(eval(input())) for i in range(N)]) h_new = [h[i + (K - 1)] - h[i] for i in range(0, N - (K - 1))] print((min(h_new)))
p03208
import heapq N, k = [int(s) for s in input().split(' ')] h = [] while len(h) != N: heapq.heappush(h, int(eval(input()))) min_height = 1000000000 h = heapq.nsmallest(N, h) 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)
N, k = [int(s) for s in input().split(' ')] h = [] while len(h) != N: h.append(int(eval(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)
p03208
N, K =list(map(int, input().split())) lst = [] for _ in range(N): lst.append(int(eval(input()))) sor = sorted(lst) mindiff = float('inf') for i in range(N-K+1): selected = sor[i:i+K] diff = selected[-1] - selected[0] if diff <= mindiff: mindiff = diff print(mindiff)
N, K =list(map(int, input().split())) lst = [] for _ in range(N): lst.append(int(eval(input()))) sor = sorted(lst) mindiff = float('inf') for i in range(N-K+1): diff = sor[i+K-1] - sor[i] if diff <= mindiff: mindiff = diff print(mindiff)
p03208
N, K = list(map(int, input().split())) h = [] for i in range(N): th = int(eval(input())) h.append(th) h.sort() ans = float('INF') for i in range(N - K + 1): ans = min(ans, h[i + K - 1] - h[i]) print(ans)
N, K = list(map(int, input().split())) h = sorted([int(eval(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)
p03208
import sys input = sys.stdin.readline def main(): N, K = list(map(int, input().split())) h = [int(eval(input())) for i in range(N)] H = sorted(h) ans = 10**9 +1 for i in range(N-K+1): high = max(H[i:i+K]) - min(H[i:i+K]) ans = min(ans, high) print(ans) if __name__ == '__main__': main()
import sys input = sys.stdin.readline def main(): N, K = list(map(int, input().split())) h = [int(eval(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()
p03208
N, K = list(map(int,input().split())) H = [] for i in range(N): H.append(int(eval(input()))) H.sort() ans = 10**9 for i in range(N-K+1): ans = min(ans, H[i+K-1]-H[i]) print(ans)
N,K = list(map(int,input().split())) T = [int(eval(input())) for i in range(N)] T.sort() P = [] for i in range(N-K+1): P.append(T[i+K-1] - T[i]) print((min(P)))
p03208
n,k = list(map(int,input().split())) c = [int(eval(input())) for _ in range(n)] c.sort() ans = [] for i in range(n-k+1): ans.append(max(c[i:k+i])-min(c[i:k+i])) print((min(ans)))
n,k = list(map(int,input().split())) c = [int(eval(input())) for _ in range(n)] c.sort() ans = [] for i in range(n-k+1): ans.append(c[i+k-1]-c[i]) print((min(ans)))
p03208
def solve(): n, k = list(map(int, input().split())) h = sorted(list(int(eval(input())) for _ in range(n))) min_diff = 10 ** 9 for i in range(n - k + 1): part = h[i:i + k] diff = part[-1] - part[0] if diff < min_diff: min_diff = diff return min_diff if __name__ == "__main__": print((solve()))
def solve(): n, k = list(map(int, input().split())) h = sorted(list(int(eval(input())) for _ in range(n))) return min(h[i + k - 1] - h[i] for i in range(n - k + 1)) if __name__ == "__main__": print((solve()))
p03208
N,K=list(map(int,input().split())) h=[] for i in range(N): h.append(int(eval(input()))) h.sort() mindiff=max(h)-min(h) for i in range(N-K+1): maxmin=max(h[i:i+K])-min(h[i:i+K]) mindiff=min(mindiff,maxmin) print(mindiff)
N,K=list(map(int,input().split())) h=[] for i in range(N): h.append(int(eval(input()))) h.sort() d=max(h)-min(h) for i in range(N-K+1): d=min(d,h[i+K-1]-h[i]) print(d)
p03208
n, k = list(map(int, input().split())) l = [0]*n for _ in range(n): l[_] = int(eval(input())) l.sort() ans = 10**9+1 for i in range(n-k+1): d = l[i+k-1]-l[i] ans = min(ans, d) print(ans)
n, k = list(map(int, input().split())) H = [int(eval(input())) for _ in range(n)] H.sort() min_ = float('inf') for i in range(n-k+1): d = H[i+k-1] - H[i] min_ = min(min_, d) print(min_)
p03208
n,k = list(map(int, input().split())) h = sorted([int(eval(input())) for _ in range(n)]) l = [0]*(n-1) for i in range(n-1): l[i] = h[i+1]-h[i] s = 0 t = float("inf") for i in range(n-k+1): p = sum(l[i:i+k-1]) if p < t: t = p s = i print((h[s+k-1] - h[s]))
n,k = list(map(int, input().split())) h = sorted([int(eval(input())) for _ in range(n)]) ans = 0 t = float("inf") for i in range(n-k+1): if abs(h[i+k-1] - h[i]) < t: t = abs(h[i+k-1] - h[i]) ans = i print((h[ans+k-1] - h[ans]))
p03208
n,k = list(map(int, input().split())) h = [[] for i in range(n)] for i in range(n): h[i] = int(eval(input())) h.sort() diff = [[] for i in range(n-1)] for i in range(n-1): diff[i] = h[i+1]-h[i] t = [[] for i in range(n-1)] t[0] = diff[0] for i in range(1,n-1): t[i] = t[i-1]+diff[i] t = [0] + t # print(h) # print(diff) # print(t) ans = float("inf") for i in range(n-k+1): a = t[i+k-1]-t[i] ans = min(ans, a) print(ans)
n,k = list(map(int, input().split())) h = [[] for i in range(n)] for i in range(n): h[i] = int(eval(input())) h.sort() ans = float("inf") for i in range(n-k+1): a = h[i+k-1]-h[i] ans = min(ans, a) print(ans)
p03208
n, k = list(map(int, input().split())) tree = [] for _ in range(n): tree.append(int(eval(input()))) tree.sort() ans = 10**9 for i in range(n-k+1): ans = min(ans, max(tree[i:i+k])-min(tree[i:i+k])) print(ans)
n, k = list(map(int, input().split())) tree = [] for _ in range(n): tree.append(int(eval(input()))) tree.sort() ans = 10**9 for i in range(n-k+1): ans = min(ans, tree[i+k-1]-tree[i]) print(ans)
p03208
n, k = list(map(int, input().split())) tree = [] for _ in range(n): tree.append(int(eval(input()))) tree.sort() ans = 10**9 for i in range(n-k+1): ans = min(ans, tree[i+k-1]-tree[i]) print(ans)
import sys sys.setrecursionlimit(10 ** 6) def input(): return sys.stdin.readline()[:-1] N, K = list(map(int, input().split())) H = [0]*N for i in range(N): H[i] = int(eval(input())) H.sort() ans = 10**10 for i in range(N-(K-1)): ans = min(ans, H[i+(K-1)]-H[i]) print(ans)
p03208
n, k = list(map(int,input().split())) h = [int(eval(input())) for i in range(n)] ans = max(h) - min(h) h.sort(reverse=True) 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 = list(map(int,input().split())) h = [int(eval(input())) for i in range(n)] h.sort(reverse=True) seed = max(h) for i in range(0,n-k+1): high = max(h[i:i+k]) - min(h[i:i+k]) if seed > high: seed = high print(seed)
p03208
n, k = list(map(int, input().split())) a = [int(eval(input())) for _ in range(n)] a.sort() ans = [] for i in range(n - k + 1): b = a[i + k - 1] - a[i] ans.append(b) print((min(ans)))
n, k = list(map(int, input().split())) a = [int(eval(input())) for _ in range(n)] a.sort() c = [a[i + k - 1] - a[i] for i in range(n - k + 1)] print((min(c)))
p03208
n, k = list(map(int, input().split())) h = [] ans = 1000000001 for i in range(n): h.append(int(eval(input()))) h.sort() for j in range(n-(k-1)): x = [] if ans == 0: break for l in range(j,j+k): x.append(h[l]) if ans == 0: break elif len(x) == k: y = x[-1]-x[0] if ans == 0: break elif ans > y: ans = y print(ans)
n, k = list(map(int, input().split())) h = [] ans = 1000000001 for i in range(n): h.append(int(eval(input()))) h.sort() for j in range(n-(k-1)): if ans == 0: break elif ans > h[j+k-1]-h[j]: ans = h[j+k-1]-h[j] print(ans)
p03208
import itertools n,k=list(map(int,input().split())) h=[int(eval(input())) for _ in range(n)] ans=float('inf') for i in itertools.permutations(h,k): tmp=max(i)-min(i) ans=min(ans,tmp) print(ans)
n,k=list(map(int,input().split())) h=[int(eval(input())) for _ in range(n)] h.sort() ans=float('inf') for i in range(n-k+1): tmp=h[i+k-1]-h[i] ans=min(tmp,ans) print(ans)
p03208
n, k = list(map(int, input().split())) h = [int(eval(input())) for _ in range(n)] h.sort() ans = 10 ** 9 for i in range(n-k+1): if h[i+k-1] - h[i] < ans: ans = h[i+k-1] - h[i] print(ans)
n,k = list(map(int, input().split())) h = [int(eval(input())) for _ in range(n)] h.sort() ans = float("INF") for i in range(n-k+1): if ans > h[i+k-1] - h[i]: ans = h[i+k-1] - h[i] print(ans)
p03208
n, k, *a = list(map(int, open(0).read().split())) a.sort() mn = 1e18 for i in range(n-k+1): tmp = 0 for j in range(k-1): tmp+=abs(a[i+j]-a[i+j+1]) mn = min(mn, tmp) print(mn)
n, k, *a = list(map(int, open(0).read().split())) a.sort() for i in range(n-1): a[n-i-1] = abs(a[n-i-1]-a[n-i-2]) a[0] = 0 for i in range(n-1): a[i+1] += a[i] mn = 1e18 for i in range(n-k+1): mn = min(mn, a[i+k-1]-a[i]) print(mn)
p03208
n, k, *a = list(map(int, open(0).read().split())) a.sort() for i in range(n-1): a[n-i-1] = abs(a[n-i-1]-a[n-i-2]) a[0] = 0 for i in range(n-1): a[i+1] += a[i] mn = 1e18 for i in range(n-k+1): mn = min(mn, a[i+k-1]-a[i]) print(mn)
n, k, *a = list(map(int, open(0).read().split())) a.sort() ans = 1e18 for i in range(n-k+1): ans = min(ans, a[i+k-1]-a[i]) print(ans)
p03208
n, k = list(map(int,input().split())) li = list(int(eval(input())) for i in range(n)) li.sort() num = 0 li2,li3 = [],[] for i in range(len(li)-k+1): li2.append(li[i:i+k]) for i in range(len(li2)): li3.append(max(li2[i]) - min(li2[i])) print((min(li3)))
n, k = list(map(int,input().split())) li = list(int(eval(input())) for i in range(n)) li.sort() num = 0 li2 = [] for i in range(len(li)-k+1): li2.append( max(li[i:i+k]) - min(li[i:i+k])) print((min(li2)))
p03208