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

#PS0000180. Tìm vị trí theo tổng tích lũy (K-th by Cumulative Sum)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tìm vị trí theo tổng tích lũy (K-th by Cumulative Sum)

K-th by Cumulative Sum

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn nonnegative integers f1,…,fnf_1,\ldots,f_n, for each positive integer query XX, find the smallest index ii (1≤i≤n1\le i\le n) satisfying ∑j=1ifj≥X\sum_{j=1}^{i} f_j\ge X. Print -1 if no such index exists. Queries do not change the array.

Input

The first line contains n,qn,q. The second contains nn integers f1,…,fnf_1,\ldots,f_n. The third contains qq thresholds X1,…,XqX_1,\ldots,X_q.

Output

Print q lines, each containing the smallest corresponding index or -1.

Subtasks

  • Subtask 1 (20 points): 1≤n≤5001\le n\le 500; 1≤q≤5001\le q\le 500; 0≤fi≤1090\le f_i\le10^9; 1≤Xj≤10181\le X_j\le10^{18}.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le 200000; 1≤q≤2000001\le q\le 200000; 0≤fi≤1090\le f_i\le10^9; 1≤Xj≤10181\le X_j\le10^{18}; f1=⋯=fnf_1=\cdots=f_n.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤q≤2000001\le q\le 200000; 0≤fi≤1090\le f_i\le10^9; 1≤Xj≤10181\le X_j\le10^{18}.

Example 1

Input

5 5
0 2 0 3 0
1 2 3 5 6

Output

2
2
4
4
-1

Explanation

The prefix totals are 0,2,2,5,5. Ticket 2 first reaches its threshold at index 2; 6 exceeds the total.

Example 2

Input

3 2
0 0 0
1 10

Output

-1
-1

Explanation

All prefix totals are zero, below every positive threshold.