#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstring>
#include <set>
#include <cmath>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, q; cin >> n >> q;
int diameters[n];
int next[n];
int capacities[n];
for (int i = 0; i < n; i++) cin >> diameters[i] >> capacities[i];
for (int i = 0; i < n; i++) {
next[i] = n;
for (int j = i + 1; j < n; j++) {
if (diameters[j] > diameters[i]) {
next[i] = j;
break;
}
}
}
for (int iq = 0; iq < q; iq++) {
int r, v; cin >> r >> v; r--;
for (; r < n; r = next[r]) {
v -= capacities[r];
if (v <= 0) break;
}
if (r == n) cout << 0 << endl;
else cout << r + 1 << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
3 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1563 ms |
1624 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 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
3 ms |
212 KB |
Output is correct |
8 |
Execution timed out |
1563 ms |
1624 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |