#include<bits/stdc++.h>
using namespace std;
#define Study ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ff first
#define ss second
#define ins insert
#define all(x) x.begin(),x.end()
#define fori(x,y,z) for(ll x=y;x<=z;x++)
const ll INF=1e9;
const ll sz=2e5+10;
const ll mod=1e9+7;
void work(){
ll n,q;
cin>>n>>q;
vector<pair<ll,ll>>v(n+1);
fori(i,1,n){
ll d,x;
cin>>d>>x;
v[i].ff=d;
v[i].ss=x;
}
while(q--){
ll d,l;
cin>>d>>l;
ll sum=v[d].ss;
ll maxr=v[d].ff;
d++;
while(d<=n and sum<l){
if(v[d].ff>maxr){
sum+=v[d].ss;
maxr=v[d].ff;
}
d++;
}
if(sum>=l)
d--;
//cout<<d<<' '<<sum<<endl;
if(sum<l and d>=n)
cout<<0<<endl;
else
cout<<d<<endl;
}
}
int main(){
Study;
ll t=1;
//cin>>t;
while(t--){
work();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |