Submission #539456

#TimeUsernameProblemLanguageResultExecution timeMemory
539456MurotYGarage (IOI09_garage)C++14
40 / 100
4 ms472 KiB
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
#define ll long long
using namespace std;
const int N=1e6+7, M=1e9+7;
ll a[N], b[N];
void solve()
{
	ll n, m;
	cin >> n >> m;
	
	for (int i=1;i<=n;i++) cin >> a[i];
	for (int i=1;i<=m;i++) cin >> b[i];
	
	map <ll,ll> mp, mp1;
	ll ans=0;
	for (int i=1;i<=2*m;i++){
		ll x;
		cin >> x;
		if (x > 0){
			for (int i=1;i<=n;i++){
				if (mp[i] == 0) {
					mp[i]=1;
					ans+=a[i]*b[x];
					mp1[x]=i;
					break;
				}
			}
		}
		else mp[mp1[-x]]=0;
	}
	cout << ans;
}
int main()
{
	ios;
	int t=1;
//	cin >> t;
	while (t--){
		solve(); 
		cout << "\n";
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...