Submission #1094907

#TimeUsernameProblemLanguageResultExecution timeMemory
1094907raphaelpBikeparking (EGOI24_bikeparking)C++14
100 / 100
97 ms11136 KiB
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; vector<long long> Tab(N), P(N); set<long long> M; for (long long i = 0; i < N; i++) { cin >> Tab[i]; } for (long long i = 0; i < N; i++) { cin >> P[i]; } long long tot = 0; stack<pair<long long, long long>> S; for (long long i = N - 2; i >= 0; i--) { S.push({P[i + 1], i + 1}); while (Tab[i] > 0 && !S.empty()) { long long temp = min(Tab[i], S.top().first); Tab[i] -= temp; tot += temp; S.top().first -= temp; P[S.top().second] -= temp; if (S.top().first == 0) S.pop(); } } for (long long i = 0; i < N; i++) { long long temp = min(Tab[i], P[i]); Tab[i] -= temp; P[i] -= temp; } for (long long i = 0; i < N; i++) tot -= P[i]; cout << tot; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...