# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
761225 | Blagoj | Garage (IOI09_garage) | C++17 | 2 ms | 340 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 endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int n, m, t;
cin >> n >> m;
t = n;
int r[n], w[m], went[m];
for (int i = 0; i < n; i++) cin >> r[i];
for (int i = 0; i < m; i++) cin >> w[i];
queue<int> q;
bool full[n];
memset(full, 0, sizeof(full));
ll ans = 0;
for (int i = 0; i < 2 * m; i++) {
int c;
cin >> c;
if (c > 0) {
c--;
if (n == 0) {
q.push(c);
continue;
}
for (int j = 0; j < t; j++) {
if (full[j]) continue;
ans += w[c] * r[j];
full[j] = 1;
went[c] = j;
n--;
break;
}
}
else {
c *= -1;
c--;
n++;
full[went[c]] = 0;
while (n > 0 && q.size() > 0) {
int f = q.front();
q.pop();
for (int j = 0; j < t; j++) {
if (full[j]) continue;
ans += w[f] * r[j];
full[j] = 1;
went[f] = j;
n--;
break;
}
}
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |