#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("file.in", "r", stdin)
//freopen("file.out", "w", stdout);
int n, m; cin >> n >> m;
int parkCost[n];
for (auto &i: parkCost) cin >> i;
int carW[m];
for (auto &i: carW) cin >> i;
int ans = 0;
vector<bool> av(n, true);
vector<int> slot(m, -1);
queue<int> q;
for (int i = 0; i < 2 * m; i++) {
int x; cin >> x;
if (x < 0) {
x = abs(x);
x--;
av[slot[x]] = true;
slot[x] = -1;
for (int j = 0; j < n; j++) {
if (q.empty()) break;
if (!av[j]) continue;
av[j] = false;
ans += carW[q.front()] * parkCost[j];
slot[q.front()] = j;
q.pop();
}
}
else {
x--;
q.push(x);
for (int j = 0; j < n; j++) {
if (q.empty()) break;
if (!av[j]) continue;
av[j] = false;
ans += carW[q.front()] * parkCost[j];
slot[q.front()] = j;
q.pop();
}
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 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 |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
464 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
524 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |