#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, ans=0, k;
cin>>n>>m;
k=n;
vector<int> a(n), b(m), what(n, -1);
for (int i=0; i<n; ++i)cin>>a[i];
for (int i=0; i<m; ++i)cin>>b[i];
queue<int> q;
for (int ooga=0, id; ooga<2*m; ++ooga){
cin>>id;
if (id<0){
++k;
id=abs(id)-1;
for (int i=0; i<n; ++i)if (what[i]==id)what[i]=-1;
}
else{
id=abs(id)-1;
q.push(id);
}
while (q.size()&&k){
for (int i=0; i<n; ++i)if (what[i]==-1){
what[i]=q.front(), ans+=a[i]*b[q.front()], --k;
break;
}
q.pop();
}
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |