PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000197. Nhiều truy vấn đếm đoạn có tổng không nhỏ hơn K (Multiple Subarray Sum Threshold Queries)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Nhiều truy vấn đếm đoạn có tổng không nhỏ hơn K (Multiple Subarray Sum Threshold Queries)

Multiple Subarray Sum Threshold Queries

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn integers and qq queries, for each integer threshold KjK_j count nonempty consecutive intervals [l,r][l,r] satisfying ∑i=lrai≥Kj\sum_{i=l}^{r}a_i\ge K_j. Queries are independent and the array never changes. Intervals at different positions are counted separately.

Input

The first line contains n,qn,q. The second contains exactly nn integers aia_i. Each of the next qq lines contains one integer KjK_j.

Output

Print qq lines, each containing the count for the corresponding query.

Subtasks

  • Subtask 1 (20 points): 1≤n≤801\le n\le 80; 1≤q≤51\le q\le5; −109≤ai≤109-10^9\le a_i\le10^9; −1012≤Kj≤1012-10^{12}\le K_j\le10^{12}.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤q≤201\le q\le20; −109≤ai≤109-10^9\le a_i\le10^9; −1012≤Kj≤1012-10^{12}\le K_j\le10^{12}; ai≥0a_i\ge0.
  • Subtask 3 (50 points): 1≤n≤20001\le n\le 2000; 1≤q≤201\le q\le20; −109≤ai≤109-10^9\le a_i\le10^9; −1012≤Kj≤1012-10^{12}\le K_j\le10^{12}.

Example 1

Input

3 4
2 -1 3
0
3
4
5

Output

5
2
1
0

Explanation

The six sums are 2, 1, 4, -1, 2, 3. Five are nonnegative, two are at least 3, one is at least 4, and none is at least 5.

Example 2

Input

2 3
0 0
0
1
-1

Output

3
0
3

Explanation

All three intervals sum to zero; thresholds 0 and -1 accept all three.