# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1082754 | toast12 | Garage (IOI09_garage) | C++14 | 4 ms | 456 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() {
int n, m;
cin >> n >> m;
vector<int> rates(n), weights(m);
for (int i = 0; i < n; i++) {
cin >> rates[i];
}
for (int i = 0; i < m; i++) {
cin >> weights[i];
}
multiset<int> available;
for (int i = 0; i < n; i++) {
available.insert(i);
}
map<int, int> lots;
queue<int> q;
long long ans = 0;
for (int i = 0; i < 2*m; i++) {
int car;
cin >> car;
if (car < 0) {
car *= -1;
car--;
if (!q.empty()) {
int car2 = q.front();
lots[car2] = lots[car];
ans += weights[car2]*rates[lots[car2]];
q.pop();
}
else {
available.insert(lots[car]);
}
lots[car] = 0;
continue;
}
car--;
if (available.empty()) {
q.push(car);
continue;
}
int lot = *(available.begin());
ans += weights[car]*rates[lot];
lots[car] = lot;
available.erase(lot);
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |