#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> vi(n);
for (auto &a : vi)
cin >> a;
vector<int> weight(m);
for (auto &a : weight)
cin >> a;
long long ans = 0;
vector<int> stat(n, -1);
queue<int> qi;
for (int i = 0; i < 2 * m; i++) {
int x;
cin >> x;
if (x < 0) {
int in = find(begin(stat), end(stat), -x) - begin(stat);
stat[in] = -1;
} else {
qi.push(x);
}
int in = 0;
for (; in < n; in++) {
if (stat[in] == -1 && !qi.empty()) {
stat[in] = qi.front();
ans += weight[stat[in] - 1] * vi[in];
qi.pop();
}
}
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |