Codeforces 975C

题意略。

思路:这题考察的是二分搜索。

#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
typedef long long LL;

LL n,q;
LL ai[maxn],ki[maxn];

int main(){
    scanf("%lld%lld",&n,&q);
    for(int i = 0;i < n;++i) scanf("%lld",&ai[i]);
    for(int i = 1;i <= q;++i) scanf("%lld",&ki[i]);
    
    for(int i = 1;i < n;++i) ai[i] += ai[i - 1];
    
    LL sum = 0;
    for(int i = 1;i <= q;++i){
        sum += ki[i];
        int die = upper_bound(ai,ai + n,sum) - ai;
        int live = n - die;
        if(live == 0){
            live = n;
            sum = 0;
        }
        printf("%d\n",live);
    }
    return 0;
} 

猜你喜欢

转载自www.cnblogs.com/tiberius/p/9158414.html