# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1078385 | sqrteipi | Garage (IOI09_garage) | C++14 | 2 ms | 348 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;
bool app[105];
int a[105], b[2005], c[2005];
int main() {
int n, m, cnt=0;
cin >> n >> m;
for (int i=0; i<n; i++) cin >> a[i];
for (int i=0; i<m; i++) cin >> b[i];
queue<int> waiting;
for (int i=0; i<2*m; i++) {
int x;
cin >> x;
if (x > 0) {
x -= 1;
int p=0;
while (p<n&&app[p]) p++;
if (p==n) waiting.push(x);
else app[p] = true, cnt += a[p] * b[x], c[x] = p;
}
else {
x = -x - 1;
app[c[x]] = false;
if (!waiting.empty()) {
int y = waiting.front();
app[c[x]] = true, cnt += a[c[x]] * b[y], c[y] = c[x];
waiting.pop();
}
}
}
cout << cnt;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |