# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
986728 | lyu | Garage (IOI09_garage) | C++17 | 2 ms | 500 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_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int parking[n];
for(int i = 0; i < n; i++) cin >> parking[i];
int weight[m];
for(int i = 0; i < m; i++) cin >> weight[i];
int status, profit = 0;
unordered_map<int, int> cars;
unordered_map<int, int> taken;
queue<int> waiting;
for(int i = 0; i < 2*m; i++) {
cin >> status;
if(status > 0) {
status--;
bool parked = false;
for(int i = 0; i < n; i++) {
if(taken.count(i) == 0) {
taken[i] = status;
cars[status] = i;
profit += parking[i] * weight[status];
parked = true;
break;
}
}
if(!parked) waiting.push(status);
}
else {
status++;
status *= -1;
int num = cars[status];
cars.erase(status);
taken.erase(num);
if(!waiting.empty()) {
int f = waiting.front();
cars[f] = num;
taken[num] = f;
profit += weight[f] * parking[num];
waiting.pop();
}
}
}
cout << profit << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |