Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created October 14, 2018 06:06
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/e43931654dafcdd565473920d4788018 to your computer and use it in GitHub Desktop.
Save whatalnk/e43931654dafcdd565473920d4788018 to your computer and use it in GitHub Desktop.
AtCoder ABC #085 D
n, h = gets.chomp.split(" ").map(&:to_i)
a = []
b = []
n.times do
a_, b_ = gets.chomp.split(" ").map(&:to_i)
a << a_
b << b_
end
amax = a.max
b.sort!
ans = 0
(n-1).downto(0) do |i|
if h <= 0
puts ans
exit
end
if b[i] > amax
h -= b[i]
ans += 1
end
end
ans += h / amax
if h % amax == 0
puts ans
else
puts ans + 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment