Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- const int N=5000005;
- int T,n,sum[N],a[N],q,l,u,x;
- signed main(){
- cin>>T;
- while(T--){
- cin>>n;
- for(int i=1;i<=n;i++){
- cin>>x;
- sum[i]=sum[i-1]+x;
- }
- cin>>q;
- while(q--){
- cin>>l>>u;
- u+=sum[l-1];
- int ans=lower_bound(sum+1,sum+1+n,u)-sum;
- if(sum[ans]-u>u-sum[ans-1]) ans--;
- ans=max(ans,l);
- ans=min(ans,n);
- cout<<ans<<" ";
- }
- cout<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement