-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathC.cpp
58 lines (47 loc) · 1.12 KB
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 2e18
ll ara[200009], lav[200009], cum[200009];
int main()
{
ll n, q, mns = 0;
cin >> n >> q;
for(ll i = 1; i <= n; i++)
scanf("%lld", &ara[i]);
for(ll i = 1; i <= q; i++)
scanf("%lld", &lav[i]);
for(ll i = 1; i <= n; i++) {
cum[i] = ara[i] + cum[i - 1];
}
ll lo = 1;
for(ll i = 1; i <= q; i++) {
ll pwr = lav[i];
//cout << " " << mns << endl;
ll hi = n, ansi = 0;
while(lo <= hi) {
ll mid = (lo + hi) / 2;
if(cum[mid] - mns > pwr) {
hi = mid - 1;
}
else if(cum[mid] - mns <= pwr) {
lo = mid + 1;
ansi = mid;
}
}
//cout << " " << ansi << endl;
ll alive = n - ansi;
if(ansi == 0) {
alive = n - lo + 1;
}
mns = pwr + mns;
lo = ansi + 1;
if(alive == 0) {
mns = 0;
alive = n;
lo = 1;
}
printf("%lld\n", alive);
}
return 0;
}