#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 105, M = 2005;
int n, m;
int cost[N], used[M], weight[M];
priority_queue<int, vector<int>, greater<int>> avail;
queue<int> q;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> cost[i];
avail.push(i);
}
for(int i = 1; i <= m; i++)
cin >> weight[i];
ll ans = 0;
for(int c = 0; c < 2*m; c++) {
int x; cin >> x;
if(x > 0) {
if(avail.empty())
q.push(x);
else
used[x] = avail.top(), avail.pop();
} else {
x *= -1;
ans += 1ll*cost[used[x]]*weight[x];
if(!q.empty())
used[q.front()] = used[x], q.pop();
else
avail.push(used[x]);
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
7 ms |
384 KB |
Output is correct |