//
// 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 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
440 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
440 KB |
Output isn't correct |
18 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
20 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |