-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Worms.cpp
More file actions
56 lines (42 loc) · 776 Bytes
/
B_Worms.cpp
File metadata and controls
56 lines (42 loc) · 776 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
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n;
cin>> n;
vector<long long> piles(n);
vector<long long> prefix(n);
for(int i=0;i<n;i++)
{
cin>> piles[i];
}
prefix[0]=piles[0];
for(int i=1;i<n;i++)
{
prefix[i]=prefix[i-1]+piles[i];
}
int q;
cin>>q;
while(q--)
{
long long worm;
cin>>worm;
int l=0, r=n-1;
int ans=-1;
while(l<=r)
{
int mid = l+(r-l)/2;
if(prefix[mid]>=worm)
{
ans=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
cout<<ans+1<<endl;
}
}