#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int parking[n];
for(int i = 0; i < n; i++) cin >> parking[i];
int weight[m];
for(int i = 0; i < m; i++) cin >> weight[i];
int status, profit = 0;
unordered_map<int, int> cars;
unordered_map<int, int> taken;
queue<int> waiting;
for(int i = 0; i < 2*m; i++) {
cin >> status;
if(status > 0) {
status--;
bool parked = false;
for(int i = 0; i < n; i++) {
if(taken.count(i) == 0) {
taken[i] = status;
cars[status] = i;
profit += parking[i] * weight[status];
parked = true;
break;
}
}
if(!parked) waiting.push(status);
}
else {
status++;
status *= -1;
int num = cars[status];
cars.erase(status);
taken.erase(num);
if(!waiting.empty()) {
int f = waiting.front();
cars[f] = num;
taken[num] = f;
profit += weight[f] * parking[num];
waiting.pop();
}
}
}
cout << profit << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 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 |
1 ms |
484 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
500 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |