#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
const int N=3e5+5;
int a[N];
bool vis[N];
int d[N],c[N];
vector<int>ans ;
int ps[N];
signed main(){
int n,q;
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>d[i]>>c[i];
}
for(int i=1;i<=n;i++){
ps[i]=ps[i-1]+c[i];
}
ps[n+1]=ps[n];
for(int i=0;i<q;i++){
int idx,v;
cin>>idx>>v;
int hi=n,lo=idx;
while(hi>=lo){
int mid=(hi+lo)/2;
if(ps[mid]-ps[idx-1]<v){
lo=mid+1;
}
else{
hi=mid-1;
}
}
if(lo==n+1)lo=0;
ans.pb(lo);
}
for(auto a:ans)cout<<a<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |