# AtCoder Beginner Contest 030

URL: https://atcoder.jp/contests/abc030 (opens new window)

# C

n,m = gets.chomp.split(" ").map(&:to_i)
x,y = gets.chomp.split(" ").map(&:to_i)
a_arr = gets.chomp.split(" ").map(&:to_i)
b_arr = gets.chomp.split(" ").map(&:to_i)

t = 0
a_i = 0
b_i = 0
result = 0

while true do
  # 次の便を探す
  while !a_arr[a_i].nil? && a_arr[a_i] < t do
    a_i += 1
  end
  break if a_arr[a_i].nil?
  # 往路
  t = a_arr[a_i] + x

  # 次の便を探す
  while !b_arr[b_i].nil? && b_arr[b_i] < t do
    b_i += 1
  end
  break if b_arr[b_i].nil?
  # 復路
  t = b_arr[b_i] + y

  # 往復できたのでインクリメント
  result += 1
end

puts result
Last Updated: 2020/08/29 17:41