Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created March 10, 2019 02:59
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/3aeb343ef9517240eb99fab8d2971989 to your computer and use it in GitHub Desktop.
Save whatalnk/3aeb343ef9517240eb99fab8d2971989 to your computer and use it in GitHub Desktop.
AtCoder ABC #121 C - Energy Drink Collector
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