-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Worms.cpp
More file actions
40 lines (37 loc) · 913 Bytes
/
B_Worms.cpp
File metadata and controls
40 lines (37 loc) · 913 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
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(NULL), cout.tie(NULL)
#define REP(i, start, end) for(auto i = start; i < end; i++)
//#define FORJ(start, end) for(auto j = start; j < end; j++)
int main(){
FASTIO;
int n;
cin >> n;
int arr[n];
int dummy[n];
int sum = 0;
REP(i, 0, n) {
cin >> arr[i];
sum+=arr[i];
dummy[i] = sum;
}
int q;
cin >>q;
while(q--){
int low=0, high = n-1;
int item;
cin >> item;
int ans;
while(low <= high){
int mid = low+ (high - low)/2;
if(dummy[mid]>=item){
ans = mid + 1;
high = mid-1;
}
if(dummy[mid] < item)
low = mid + 1;
}
cout << ans << endl;
}
return 0;
}