# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1005586 | SpyrosAliv | Garage (IOI09_garage) | C++14 | 1 ms | 524 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;
#define int long long
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("file.in", "r", stdin)
//freopen("file.out", "w", stdout);
int n, m; cin >> n >> m;
int parkCost[n];
for (auto &i: parkCost) cin >> i;
int carW[m];
for (auto &i: carW) cin >> i;
int ans = 0;
vector<bool> av(n, true);
vector<int> slot(m, -1);
queue<int> q;
for (int i = 0; i < 2 * m; i++) {
int x; cin >> x;
if (x < 0) {
x = abs(x);
x--;
av[slot[x]] = true;
slot[x] = -1;
for (int j = 0; j < n; j++) {
if (q.empty()) break;
if (!av[j]) continue;
av[j] = false;
ans += carW[q.front()] * parkCost[j];
slot[q.front()] = j;
q.pop();
}
}
else {
x--;
q.push(x);
for (int j = 0; j < n; j++) {
if (q.empty()) break;
if (!av[j]) continue;
av[j] = false;
ans += carW[q.front()] * parkCost[j];
slot[q.front()] = j;
q.pop();
}
}
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |