#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100, MAX_M = 2000;
using ll = long long;
bool taken[1 + MAX_N];
bool wasted[1 + MAX_M];
int parked_at[1 + MAX_M];
int main () {
ios::sync_with_stdio (false);
cin.tie (0); cout.tie (0);
int n, m;
cin >> n >> m;
vector <int> r (n + 1), w (m + 1);
for (int i = 1; i <= n; i++)
cin >> r[i];
for (int i = 1; i <= m; i++)
cin >> w[i];
queue <int> car_line;
ll ans = 0;
for (int i = 1; i <= 2 * m; i++) {
int t;
cin >> t;
if (t > 0)
car_line.push (t);
else {
t = -t;
wasted[t] = true;
if (parked_at[t])
taken[parked_at[t]] = false;
}
while (car_line.size () && wasted[car_line.front ()])
car_line.pop ();
if (car_line.size ()) {
int space = 1;
while (space <= n && taken[space])
space++;
if (space <= n) {
taken[space] = true;
parked_at[car_line.front ()] = space;
ans += w[car_line.front ()] * r[space];
car_line.pop ();
}
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |