# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
252052 | yuma220284 | Garage (IOI09_garage) | C++14 | 3 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;
int main() {
int N, M;
cin >> N >> M;
vector<int> R(N), W(M), NOW(M, -1);
queue<int> Q;
priority_queue<int, vector<int>, greater<int> > PQ;
for (int i = 0; i < N; i++) cin >> R[i];
for (int i = 0; i < M; i++) cin >> W[i];
for (int i = 0; i < N; i++) {
PQ.push(i);
}
int ANS = 0;
for (int i = 0; i < M * 2; i++) {
int X;
cin >> X;
if (X >= 0) {
X--;
if (PQ.empty()) {
Q.push(X);
}
else {
int Y = PQ.top();
PQ.pop();
ANS += R[Y] * W[X];
NOW[X] = Y;
}
}
else {
X = -X;
X--;
if (Q.empty()) {
PQ.push(NOW[X]);
NOW[X] = -1;
}
else {
NOW[Q.front()] = NOW[X];
ANS += R[NOW[X]] * W[Q.front()];
NOW[X] = -1;
Q.pop();
}
}
}
cout << ANS << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |