Advertisement
Ankit_132

E

Feb 27th, 2024
1,040
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. const int N=5000005;
  5.  
  6. int T,n,sum[N],a[N],q,l,u,x;
  7.  
  8. signed main(){
  9.     cin>>T;
  10.     while(T--){
  11.         cin>>n;
  12.         for(int i=1;i<=n;i++){
  13.             cin>>x;
  14.             sum[i]=sum[i-1]+x;
  15.         }
  16.        
  17.         cin>>q;
  18.         while(q--){
  19.             cin>>l>>u;
  20.             u+=sum[l-1];
  21.             int ans=lower_bound(sum+1,sum+1+n,u)-sum;
  22.             if(sum[ans]-u>u-sum[ans-1])     ans--;
  23.             ans=max(ans,l);
  24.             ans=min(ans,n);
  25.             cout<<ans<<" ";
  26.         }
  27.         cout<<"\n";
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement