# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
311619 | ipaljak | Garage (IOI09_garage) | C++14 | 2 ms | 384 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 MAXN = 105;
const int MAXM = 2010;
int n, m;
int r[MAXN], w[MAXM], park[MAXM];
set<int> sp;
int main(void) {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) scanf("%d", &r[i]);
for (int i = 0; i < m; ++i) scanf("%d", &w[i]);
for (int i = 0; i < n; ++i) sp.insert(i);
queue<int> q;
int sol = 0;
for (int i = 0; i < 2 * m; ++i) {
int x;
scanf("%d", &x);
if (x > 0) {
--x;
if (sp.empty()) {
q.push(x);
continue;
}
sol += r[*sp.begin()] * w[x];
park[x] = *sp.begin();
sp.erase(sp.begin());
} else {
x = abs(x); --x;
sp.insert(park[x]);
if (!q.empty()) {
int x = q.front(); q.pop();
sol += r[*sp.begin()] * w[x];
park[x] = *sp.begin();
sp.erase(sp.begin());
}
}
}
printf("%d\n", sol);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |