Submission #1255046

#TimeUsernameProblemLanguageResultExecution timeMemory
1255046__ugur__Fountain (eJOI20_fountain)C++20
30 / 100
1594 ms1608 KiB
#include <iostream> #include <cstdint> #include <vector> #include <stack> #include <math.h> using namespace std; vector<int> diameters; // D vector<int> capacities; // C vector<int> next_drain; // next higher, min D (like pointer) int main() { int N, Q; cin >> N >> Q; diameters = vector<int>(N+1, 0); capacities = vector<int>(N+1, 0); next_drain = vector<int>(N+1, -1); for(int i=1; i<=N; i++) { int temp; cin >> temp; diameters[i] = temp; cin >> temp; capacities[i] = temp; } { stack<int> s; // next_drain'leri bulcazz for(int i=1; i<N; i++) { int next = diameters[i+1]; if(diameters[i] < next) next_drain[i] = i+1; else s.push(i); while(s.size() && diameters[s.top()] < next) { next_drain[s.top()] = i+1; s.pop(); } } } while(Q--) { int start, vol; cin >> start >> vol; while(1) { vol -= capacities[start]; if(vol > 0) { start = next_drain[start]; if(start == -1) { cout << "0\n"; goto next_query; } continue; } cout << start << '\n'; goto next_query; } next_query: continue; } return 0; } //6 5 4 10 6 8 3 5 4 14 10 9 4 20 1 25 6 30 5 8 3 13 2 8
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...