Submission #1219601

#TimeUsernameProblemLanguageResultExecution timeMemory
1219601toast12Bikeparking (EGOI24_bikeparking)C++20
100 / 100
81 ms4796 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; int up = 0, down = 0; vector<int> v; for (int i = 0; i < n; i++) { while (!v.empty()) { // assign as many users as possible to the nearest better slot than their chosen one if (b[i] == 0) break; if (a[v.back()] == 0) { v.pop_back(); continue; } int temp = min(a[v.back()], b[i]); up += temp; b[i] -= temp; a[v.back()] -= temp; } v.push_back(i); } for (int i = 0; i < n; i++) { // try to get as many neutral votes as possible int temp = min(a[i], b[i]); a[i] -= temp; b[i] -= temp; // the people left will downvote down += b[i]; } cout << up-down << '\n'; return 0; }
#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...