# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
300249 | fpc_coder | Garage (IOI09_garage) | C++17 | 4 ms | 512 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;
const int N = 105;
const int M = 2005;
int w[M], r[N], pos[M];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> r[i];
for (int i = 1; i <= m; i++) cin >> w[i];
queue<int> wait;
vector<int> empty_pos(n);
for (int i = 0; i < n; i++) empty_pos[i] = i + 1;
int ans = 0;
for (int i = 0; i < 2 * m; i++) {
int car;
cin >> car;
if (car > 0) {
if (!empty_pos.empty()) {
vector<int>::iterator mn_it = min_element(empty_pos.begin(), empty_pos.end());
int mn_pos = *mn_it;
ans += w[car] * r[mn_pos];
pos[car] = mn_pos;
empty_pos.erase(mn_it);
}
else wait.push(car);
}
else {
car = -car;
if (!wait.empty()) {
int waiting = wait.front(); wait.pop();
pos[waiting] = pos[car];
ans += w[waiting] * r[pos[waiting]];
}
else empty_pos.push_back(pos[car]);
}
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |