#include <bits/stdc++.h>
#define all(v) ((v).begin(),(v).end())
typedef long long ll;
using namespace std;
const int mod = 1e9 + 7;
const int mxN = 2e6 + 1;
pair<int,int> a[mxN];
int main()
{
ios::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;
}
a[n].first = INT_MAX;a[n].second = INT_MAX;
while(q--){
int r,v;
cin >>r>>v;
int prev = a[r - 1].first - 1;
for(int i = r - 1;i <= n;i++){
if(a[i].first > prev){
prev = a[i].first;
v -= a[i].second;
}
if(v <= 0){
if(i == n)
cout<<0<<'\n';
else
cout <<i + 1<<'\n';
break;
}
}
}
}
// nice
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1581 ms |
1348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Execution timed out |
1581 ms |
1348 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |