forked from anandadfoxx/codeforces_solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path474B.cpp
More file actions
43 lines (34 loc) · 716 Bytes
/
Copy path474B.cpp
File metadata and controls
43 lines (34 loc) · 716 Bytes
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
#include <bits/stdc++.h>
#define FOR(i, start, end) for(int i = start; i < end; i++)
using namespace std;
typedef long long LL;
int n;
int search(LL* arr, LL x) {
int l = 0, r = n-1;
while (l <= r) {
int m = (l + r) >> 1;
if (x > arr[m]) l = m + 1;
else {
if (x > arr[m-1] && x <= arr[m] || (m == 0 || m == n-1)) return m;
else r = m - 1;
}
}
return -1;
}
int main() {
cin >> n;
LL cnt = 0, arr[n];
FOR(i, 0, n) {
int x;
cin >> x;
cnt += x;
arr[i] = cnt;
}
int m;
cin >> m;
while (m--) {
LL q;
cin >> q;
cout << search(arr, q) + 1 << '\n';
}
}