This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
const ll sz=1005;
ll l[sz], s[sz];
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll n, q;
cin>>n>>q;
for(int i=1; i<=n; i++){
cin>>l[i]>>s[i];
}
while(q--){
ll in, k;
cin>>in>>k;
k-=s[in];
if(k<=0){
cout<<in<<endl;
continue;
}
ll last=l[in], ans;
for(int i=in+1; i<=n; i++){
if(l[i]>last){
k-=s[i];
last=l[i];
if(k<=0){
ans=i;
break;
}
}
}
if(k>0){
cout<<0<<endl;
}
else{
cout<<ans<<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... |