Created
January 11, 2019 08:44
-
-
Save whatalnk/3097c19ab2f9e843b36f74a2466b92a5 to your computer and use it in GitHub Desktop.
AtCoder ABC #115 C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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