Codeforces Round #478 (Div. 2) C. Valhalla Siege

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 n

warriors, he places them on a straight line in front of the main gate, in a way that the i-th warrior stands right after (i−1)

-th warrior. The first warrior leads the attack.

Each attacker can take up to ai

arrows before he falls to the ground, where ai is the i

-th warrior's strength.

Lagertha orders her warriors to shoot ki

arrows during the i-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 t, they will all be standing to fight at the end of minute t

.

The battle will last for q

minutes, after each minute you should tell Ivar what is the number of his standing warriors.

Input

The first line contains two integers n

and q (1≤n,q≤200000

) — the number of warriors and the number of minutes in the battle.

The second line contains n

integers a1,a2,…,an (1≤ai≤109

) that represent the warriors' strengths.

The third line contains q

integers k1,k2,…,kq (1≤ki≤1014), the i-th of them represents Lagertha's order at the i-th minute: ki

arrows will attack the warriors.

Output

Output q

lines, the i-th of them is the number of standing warriors after the i

-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
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const ll maxn=200005;
ll a[maxn];
ll sum[maxn];
ll kil[maxn];
int main()
{
	ll n,q;
	scanf("%lld %lld",&n,&q);
	sum[0]=0;
	for(ll i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	for(ll i=1;i<=q;i++){
		scanf("%lld",&kil[i]);
	}
	/*
	for(ll i=1;i<=n;i++){
		printf("%lld ",sum[i]);
	}
	printf("\n");
	*/
	ll pos=1;
	ll xsu=0;
	for(ll i=1;i<=q;i++){
		int f=pos;
		pos=lower_bound(sum,sum+n+1,kil[i]+sum[pos-1]+xsu)-sum;
		//printf("----\n");
		//printf("f==%lld xsu==%lld\n",f,xsu);
		//printf("pos==%lld\n",pos);
		if(pos==n+1){
			printf("%lld\n",n);
			xsu=0;
			pos=1;
		}else if(pos==n&&kil[i]+sum[f-1]+xsu==sum[n]){
			printf("%lld\n",n);
			xsu=0;
			pos=1;
		}else{
			if(sum[pos]==kil[i]+sum[f-1]+xsu){
				printf("%lld\n",n-pos);
				pos=pos+1;
				xsu=0;
			}else{
				printf("%lld\n",n-pos+1);
				xsu=(kil[i]+sum[f-1]+xsu)-sum[pos-1];
			}
		}
		
		//printf("-----\n");
	}
	
	
	return 0;
 } 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值