# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
309189 | BERNARB01 | Garage (IOI09_garage) | C++17 | 1 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |