#include<bits/stdc++.h>
#include<string.h>
#include <algorithm>
#include <stdlib.h>
#define ll long long
using namespace std;
ll a,b,c,d,e,f,m,i,j,n,h,g,l,r,ka,p,t[1000005];
map<ll,ll> maa,mii,mee;
vector<ll> vas,vis,vii;
pair<ll,ll> fgh,k[1000005];
string x[1000];
int main(){
cin>>a>>b;
for(i=1 ; i<=a ; i++){
cin>>k[i].first>>k[i].second;
}
k[a+1].first=100000000000;
k[a+1].second=100000000000;
if(a<=1000 && b<=2000){
while(b--){
cin>>c>>d;
g=k[c].first;
h=k[c].second;
if(h>=d){
cout<<c<<endl;
continue;
}
for(i=c+1 ; i<=a+1 ; i++){
if(k[i].first>g){
g=k[i].first;
h-=k[i].second;
}
if(h<=0){
break;
}
}
if(i==a+1){
cout<<0<<endl;
continue;
}
cout<<i<<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... |