#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int MOD = 1e9 + 7;
pair<int,int> a[100000];
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,q;
cin >> n>>q;
for(int i=0;i<n;i++){
cin >> a[i].first>>a[i].second;
}
while(q--){
int r,v;
cin >>r >> v;
int cur=0;
int ans=0;
for(int i=r-1;i<n;i++){
if(a[i].first>=cur){
cur=a[i].first;
v-=a[i].second;
ans=i+1;
if(v<=0) {
break;
}
}
}
if(v>0)ans=0;
cout<<ans<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1566 ms |
2364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |