# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
885878 | Matjaz | Garage (IOI09_garage) | C++14 | 1 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//
// GarageIOI2009.cpp
//
//
// Created by Matjaz Leonardis on 10/12/2023.
//
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int N,M;
int main(){
cin >> N >> M;
vector<int> R(N);
vector<int> W(M);
for (int i=0;i<N;i++) cin >> R[i];
for (int i=0;i<M;i++) cin >> W[i];
priority_queue<int, vector<int>, greater<int> > free_spaces;
queue<int> waiting;
for (int i=0;i<N;i++) free_spaces.push(i);
vector<int> place(M);
for (int i=0;i<2*M;i++){
int event;
cin >> event;
if (event < 0){
event *= -1;
event--;
free_spaces.push(place[event]);
if (!waiting.empty()){
place[waiting.front()] = free_spaces.top();
waiting.pop();
free_spaces.pop();
}
} else {
event--;
if (free_spaces.empty()){
waiting.push(event);
} else {
place[event] = free_spaces.top();
free_spaces.pop();
}
}
}
int total = 0;
for (int i=0;i<M;i++) total += W[i] * R[place[i]];
cout << total << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |