//
// 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> 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |