N, Q = gets.split.map(&:to_i) B = N.times.map { gets.split.map(&:to_i) } X = gets.split.map(&:to_i) def f(pos, limit) cost = 0 B.each do |x, w| cost += w * (pos - x).abs end cost <= limit end X.each do |x| ng = 0 ok = 10 ** 18 while (ok - ng).abs >= 2 limit = (ok + ng) / 2 if f(x, limit) ok = limit else ng = limit end end puts ok end