# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
870140 | inawah | Garage (IOI09_garage) | C++14 | 1 ms | 600 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 <cstdio>
#include <queue>
using namespace std;
#define MAXN 105
#define MAXM 2005
int r[MAXN], w[MAXM], p[MAXM];
queue<int> q;
bool vis[MAXN];
int main() {
int N, M;
scanf("%d %d\n", &N, &M);
for (int i = 1; i <= N; ++i) {
scanf("%d\n", &r[i]);
}
for (int i = 1; i <= M; ++i) {
scanf("%d\n", &w[i]);
}
int ans = 0;
for (int i = 1; i <= 2*M; ++i) {
int a;
scanf("%d\n", &a);
if (a > 0) {
int j;
for (j = 1; j <= N && vis[j]; ++j);
if (j <= N) {
vis[j] = true;
p[a] = j;
} else {
q.push(a);
}
} else {
vis[p[-a]] = false;
if (!q.empty()) {
int f = q.front();
p[f] = p[-a];
vis[p[f]] = true;
q.pop();
}
ans += w[-a]*r[p[-a]];
}
}
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |