CF BUDDY
← Problems·

975C · Valhalla Siege

1400 · binary search

Problem: Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.

Ivar has nn warriors, he places them on a straight line in front of the main gate, in a way that the ii-th warrior stands right after (i1)(i-1)-th warrior. The first warrior leads the attack.

Each attacker can take up to aia_i arrows before he falls to the ground, where aia_i is the ii-th warrior's strength.

Lagertha orders her warriors to shoot kik_i arrows during the ii-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute tt, they will all be standing to fight at the end of minute tt.

The battle will last for qq minutes, after each minute you should tell Ivar what is the number of his standing warriors.

Input Format: The first line contains two integers nn and qq (1n,q2000001 \le n, q \leq 200\,000) — the number of warriors and the number of minutes in the battle.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \leq a_i \leq 10^9) that represent the warriors' strengths.

The third line contains qq integers k1,k2,,kqk_1, k_2, \ldots, k_q (1ki10141 \leq k_i \leq 10^{14}), the ii-th of them represents Lagertha's order at the ii-th minute: kik_i arrows will attack the warriors.

Output Format: Output qq lines, the ii-th of them is the number of standing warriors after the ii-th minute.

Note: In the first example:

  • after the 1-st minute, the 1-st and 2-nd warriors die.
  • after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive.
  • after the 3-rd minute, the 1-st warrior dies.
  • after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1.
  • after the 5-th minute, the 2-nd warrior dies.

Sample Cases

Case 1

Input

5 5
1 2 1 2 1
3 10 1 1 1

Output

3
5
4
4
3

Case 2

Input

4 4
1 2 3 4
9 1 10 6

Output

1
4
4
1

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback