Submission #309189

#TimeUsernameProblemLanguageResultExecution timeMemory
309189BERNARB01Garage (IOI09_garage)C++17
100 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<int> r(n), w(m), e(2 * m); for (auto& x : r) { cin >> x; } for (auto& x : w) { cin >> x; } for (auto& x : e) { cin >> x; } set<int> s; for (int i = 0; i < n; i++) { s.insert(i); } queue<int> q; vector<int> taken(m); long long ans = 0; for (const auto& x : e) { int i = abs(x) - 1; if (x < 0) { s.insert(taken[i]); } else { if (!s.empty()) { ans += r[*s.begin()] * w[i]; taken[i] = *s.begin(); s.erase(s.begin()); } else { q.push(i); } } while (!s.empty() && !q.empty()) { int j = q.front(); q.pop(); ans += r[*s.begin()] * w[j]; taken[j] = *s.begin(); s.erase(s.begin()); } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...