# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
252052 | yuma220284 | Garage (IOI09_garage) | C++14 | 3 ms | 384 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |