N, K = gets.split.map(&:to_i) A = gets.split.map(&:to_i) S = [] sum = A.take(K - 1).sum (K - 1).upto(N - 1) do |i| sum += A[i] S << sum sum -= A[i - K + 1] end S.sort! Q = gets.to_i Q.times do x = gets.to_i idx = S.bsearch_index { |s| s > x } || S.size pp idx end