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 <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstring>
#include <set>
#include <cmath>
using namespace std;
int diameters[100000];
int nextf[100000];
int capacities[100000];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, q; cin >> n >> q;
for (int i = 0; i < n; i++) cin >> diameters[i] >> capacities[i];
for (int i = 0; i < n; i++) {
nextf[i] = n;
for (int j = i + 1; j < n; j++) {
if (diameters[j] > diameters[i]) {
nextf[i] = j;
break;
}
}
}
for (int iq = 0; iq < q; iq++) {
int r, v; cin >> r >> v; r--;
for (; r < n; r = nextf[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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |