#include <bits/stdc++.h>
using namespace std;
signed main(){
int n, m; cin >> n >> m;
vector <int> R(n), w(m);
for ( auto &x: R ) cin >> x;
for ( auto &v: w ) cin >> v;
vector <int> p(n, -1);
queue <int> q;
int ans = 0;
for ( int i = 0; i < m * 2; i++ ){
int x; cin >> x;
if ( x < 0 ){
for ( auto &v: p ){
if ( v == -x ) v = -1;
}
} else q.push(x);
for ( int j = 0; j < n; j++ ){
if ( p[j] == -1 && !q.empty() ){
int x = q.front(); q.pop();
ans += w[x - 1] * R[j];
p[j] = x;
}
}
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |