[Codeforces] 478 C. Valhalla Siege
題目連結:http://codeforces.com/contest/975/problem/C
巧思一下,運用前綴和的概念之類的。
巧思一下,運用前綴和的概念之類的。
#include<bits/stdc++.h> #define debug(a) cout << #a << " = " << a << endl; #define pb push_back #define all(v) (v).begin(),(v).end() #define int long long using namespace std; int n,q; int a[200009]; int k[200009]; main() { cin >> n >> q; for(int i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i-1]; } int die = 0, sol = 0; for(int i = 1; i <= q; i++) { cin >> k[i]; k[i] += k[i-1]; int d = upper_bound(a+1,a+n+1,k[i])-a; if(d == n+1) { cout << n << endl; k[i] = 0; } else cout << n+1-d << endl; } }
留言
張貼留言