C. Valhalla Siege
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 (i−1)(i−1)-th warrior. The first warrior leads the attack.
Each attacker can take up to aiai arrows before he falls to the ground, where aiai is the ii-th warrior's strength.
Lagertha orders her warriors to shoot kiki 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
The first line contains two integers nn and qq (1≤n,q≤2000001≤n,q≤200000) — the number of warriors and the number of minutes in the battle.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) that represent the warriors' strengths.
The third line contains qq integers k1,k2,…,kqk1,k2,…,kq (1≤ki≤10141≤ki≤1014), the ii-th of them represents Lagertha's order at the ii-th minute: kiki arrows will attack the warriors.
Output
Output qq lines, the ii-th of them is the number of standing warriors after the ii-th minute.
Examples
input
Copy
5 5 1 2 1 2 1 3 10 1 1 1
output
Copy
3 5 4 4 3
input
Copy
4 4 1 2 3 4 9 1 10 6
output
Copy
1 4 4 1
Note
In the first example:
题意:有一列n个勇士,他们将会承受q分钟的箭击,第i个人承受值为a[i],第j分钟会有攻击值为k[j]的箭击,当第i个人受到大小为a[i]的箭击后将会倒下,该分钟剩余的攻击将会作用于倒下的人的后面的人身上,当某分钟所有人均倒下时,那么所有人将会在该分钟满血复活,而该分钟剩余的攻击值将会无效,即该分钟后所有人的承受值重新加满,都站着。求对于每分钟攻击后,有多少人存活。
题解:首先求a[i]的前缀和sum[ ],然后对于每分钟都仔细分析:对于当前分钟,根据上一分钟攻击到的位置pos及攻击到的勇士被消耗的值的大小xsu,做这一步的判断,并且更新pos与xsu;具体思路看代码。
代码如下:
#include
#include
#include
#include
#include