Created
March 10, 2019 02:59
-
-
Save whatalnk/3aeb343ef9517240eb99fab8d2971989 to your computer and use it in GitHub Desktop.
AtCoder ABC #121 C - Energy Drink Collector
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) | |
ab = [] | |
N.times do | |
ab << gets.chomp.split(" ").map(&:to_i) | |
end | |
ab.sort_by!{|x| x[0]} | |
mrem = M | |
ans = 0 | |
N.times do |i| | |
a, b = ab[i] | |
buy = [mrem, b].min | |
ans += a * buy | |
mrem -= buy | |
if mrem == 0 | |
puts ans | |
exit | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment