Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created January 11, 2019 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/3097c19ab2f9e843b36f74a2466b92a5 to your computer and use it in GitHub Desktop.
Save whatalnk/3097c19ab2f9e843b36f74a2466b92a5 to your computer and use it in GitHub Desktop.
AtCoder ABC #115 C
# https://atcoder.jp/contests/abc115/submissions/3976642
n, k = gets.chomp.split(" ").map(&:to_i)
a = []
n.times do
a << gets.chomp.to_i
end
a.sort!
ret = a[n-1] - a[0]
(0..(n-k)).each do |i|
x = a[i+k-1] - a[i]
if x < ret
ret = x
end
end
puts ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment