#include <bits/stdc++.h>
using namespace std;
struct Reservoir {
int id, diameter, capacity;
};
int main () {
int n, nbQ; cin >> n >> nbQ;
vector<Reservoir> reservoirs(n);
for (int i = 0; i < n; i++) {
cin >> reservoirs[i].diameter >> reservoirs[i].capacity;
reservoirs[i].id = i;
}
stack<Reservoir> maximums;
maximums.push({n, int(1e9), int(1e9)});
vector<int> g(n);
for (int i = n - 1; i >= 0; i--) {
while (reservoirs[i].diameter > maximums.top().diameter) {
maximums.pop();
}
g[reservoirs[i].id] = maximums.top().id;
maximums.push({i, reservoirs[i].diameter, reservoirs[i].capacity});
}
for (int i = 0; i < n; i++) {
cout << i + 1 << " " << g[i] + 1 << '\n';
}
for (int i = 0; i < nbQ; i++) {
int iR, vol; cin >> iR >> vol;
iR--;
int sum = 0;
while (true) {
if (iR == n) {
cout << 0 << '\n';
break;
}
else if (sum + reservoirs[iR].capacity >= vol) {
cout << iR + 1 << '\n';
break;
}
else {
sum += reservoirs[iR].capacity;
iR = g[iR];
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1580 ms |
5896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |