#include <iostream>
#include <queue>
using namespace std;
int n, m;
int const NMAX = 100;
int arr[1 + NMAX];
int taken[1 + NMAX];
int const MMAX = 2000;
int weight[1 + MMAX];
int pos[1 + MMAX];
queue <int> q;
int main() {
cin >> n >> m;
for(int i = 1;i <= n;i++) {
cin >> arr[i];
}
for(int i = 1;i <= m;i++) {
cin >> weight[i];
}
int canPark = n, ans = 0;
for(int t = 1;t <= 2 * m;t++) {
int c;
cin >> c;
if(c > 0) {
if(canPark == 0) {
q.push(c);
}else {
bool foundSpot = false;
for(int i = 1;i <= n && !foundSpot;i++) {
if(taken[i] == false) {
ans += arr[i] * weight[c];
taken[i] = true;
foundSpot = true;
canPark--;
pos[c] = i;
}
}
}
} else {
c = -c;
if(canPark == 0) {
if(!q.empty()) {
ans += arr[pos[c]] * weight[q.front()];
pos[q.front()] = pos[c];
q.pop();
}else{
taken[pos[c]] = false;
canPark++;
}
} else {
taken[pos[c]] = false;
canPark++;
}
}
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
436 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 |