# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1075286 | mochifr | Garage (IOI09_garage) | C++17 | 2 ms | 432 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>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, m; cin >> n >> m;
vector<int> slot_prices(n);
vector<int> car_weights(m);
for (int i = 0; i < n; i++)
cin >> slot_prices[i];
for (int i = 0; i < m; i++)
cin >> car_weights[i];
set<int> available_slots;
for (int i = 0; i < n; i++) {
available_slots.insert(i);
}
vector<int> taken_slot(m, 0);
queue<int> car_queue;
int money = 0;
for (int i = 0; i < 2 * m; i++) {
int c; cin >> c;
if (c > 0) {
c--;
if (available_slots.empty()) {
car_queue.push(c);
continue;
}
int s = *available_slots.begin();
int sc = s;
available_slots.erase(s);
taken_slot[c] = sc;
money += car_weights[c] * slot_prices[sc];
} else if (c < 0) {
c = -c;
c--;
available_slots.insert(taken_slot[c]);
if (!car_queue.empty()) {
int oc = c;
c = car_queue.front();
car_queue.pop();
int s = *available_slots.begin();
int sc = s;
available_slots.erase(s);
taken_slot[c] = sc;
money += car_weights[c] * slot_prices[sc];
}
} else {
cout << "?" << endl;
}
}
cout << money << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |