Created
April 18, 2019 10:36
-
-
Save whatalnk/a6d71fefa409def2486e066bbc0ba167 to your computer and use it in GitHub Desktop.
AtCoder ABC #117 C - Streamline
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
n, m = gets.chomp.split(" ").map(&:to_i) | |
x = gets.chomp.split(" ").map(&:to_i).sort | |
y = Array.new(m - 1, 0) | |
(m - 1).times do |i| | |
y[i] = x[i + 1] - x[i] | |
end | |
y.sort! | |
xmax = x.last | |
xmin = x.first | |
ymaxs = y.last(n - 1) | |
if ymaxs.empty? | |
ysum = 0 | |
else | |
ysum = ymaxs.inject(:+) | |
end | |
puts xmax - xmin - ysum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment