Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created September 27, 2017 08:40
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/639628f13d478c8628e2f54d676d5187 to your computer and use it in GitHub Desktop.
Save whatalnk/639628f13d478c8628e2f54d676d5187 to your computer and use it in GitHub Desktop.
AtCoder ABC #024 C. 民族大移動
n, d, k = gets.chomp.split(" ").map(&:to_i)
lr = []
d.times do
l, r = gets.chomp.split(" ").map(&:to_i)
lr << [l, r]
end
k.times do
s, t = gets.chomp.split(" ").map(&:to_i)
curr = s
ans = 0
lr.each do |l, r|
if l <= curr && r >= curr then
if l <= t && r >= t then
ans += 1
break
end
if (t - l).abs < (t - r).abs then
curr = l
else
curr = r
end
end
ans += 1
end
puts ans
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment