Submission #772476

#TimeUsernameProblemLanguageResultExecution timeMemory
772476BlockOGFountain (eJOI20_fountain)C++14
60 / 100
1584 ms21940 KiB
#include <iostream> using namespace std; /* 6 5 4 10 6 8 3 5 4 14 10 9 4 20 1 25 6 30 5 8 3 13 2 8 */ int main() { int n, q; cin >> n >> q; int diameters[n]; int capacities[n]; for (int i = 0; i < n; i++) cin >> diameters[i] >> capacities[i]; int next[n][20]; int sum[n][20]; for (int i = 0; i < n; i++) { next[i][0] = -1; sum[i][0] = capacities[i]; for (int j = i + 1; j < n; j++) { if (diameters[j] > diameters[i]) { next[i][0] = j; break; } } } for (int j = 1; j < 20; j++) { for (int i = 0; i < n; i++) { if (next[i][j - 1] == -1) { next[i][j] = -1; sum[i][j] = sum[i][j - 1]; continue; } next[i][j] = next[next[i][j - 1]][j - 1]; sum[i][j] = sum[i][j - 1] + sum[next[i][j - 1]][j - 1]; } } for (int i = 0; i < q; i++) { int r, v; cin >> r >> v; r--; for (int i = 19; i >= 0; i--) { if (sum[r][i] >= v) continue; v -= sum[r][i]; r = next[r][i]; if (r == -1) break; } cout << r + 1 << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...