N, K = gets.split(" ").map{|s| s.to_i} a = gets.split(" ").map{|s| s.to_i} Q = gets.to_i q = [] Q.times { q << gets.to_i } S = [a[0,K].sum] 0.upto(N-K-1) {|i| S << S[-1] - a[i] + a[i+K] } S.sort! q.each {|x| if S[0] > x then puts 0 elsif S[-1] <= x then puts S.length else puts S.bsearch_index{|y| y > x} end }