#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(c) (c).begin(), (c).end()
#define MIN(a, b) ((a) = min((a), (b)))
#define MAX(a, b) ((a) = max((a), (b)))
const ll MOD = 1e9+7;
const int abc = 'z'-'a'+1;
int n, q;
vector<int> d, c;
vector<int> v;
void solve(){
cin>>n>>q;
d.resize(n); c.resize(n);
for(int i = 0; i < n; i++){
cin>>d[i]>>c[i];
}
v.resize(n);
stack<int> s;
for(int i = n-1; i >= 0; i--){
while(!s.empty() && d[s.top()] <= d[i])s.pop();
if(s.empty())v[i] = n;
else v[i] = s.top();
s.push(i);
}
while(q--){
int a, b; cin>>a>>b; a--;
b -= c[a];
while(b > 0 && a < n){
a = v[a];
b -= c[a];
}
cout<<(a+1)%(n+1)<<endl;
}
cout<<endl;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int _t;
_t = 1;
while(_t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
332 KB |
Output is correct |
5 |
Correct |
6 ms |
204 KB |
Output is correct |
6 |
Correct |
6 ms |
204 KB |
Output is correct |
7 |
Correct |
4 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1582 ms |
1976 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
332 KB |
Output is correct |
5 |
Correct |
6 ms |
204 KB |
Output is correct |
6 |
Correct |
6 ms |
204 KB |
Output is correct |
7 |
Correct |
4 ms |
204 KB |
Output is correct |
8 |
Execution timed out |
1582 ms |
1976 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |