제출 #99199

#제출 시각아이디문제언어결과실행 시간메모리
99199figter001Garage (IOI09_garage)C++14
100 / 100
6 ms384 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const ll oo = 1e18;
const ll mod = 1e9+7;
const int nax = 110;
const int mx = 2010;

ll r[nax],w[mx],at[mx];

int main(){
	#ifndef ONLINE_JUDGE
		// freopen("input.txt","r",stdin);
	#endif
	int n,m;
	cin>>n>>m;
	set<int> st;
	for(int i=1;i<=n;i++){
		st.insert(i);
		cin>>r[i];
	}
	for(int i=1;i<=m;i++)
		cin>>w[i];
	ll ans = 0;
	queue<int> q;
	for(int i=1;i<=2*m;i++){
		int t;
		cin>>t;
		if(t > 0){
			q.push(t);
		}else{
			t = -t;
			st.insert(at[t]);
		}
		while(q.size() && st.size()){
			t = q.front();
			q.pop();
			at[t] = *st.begin();
			ans += w[t] * r[at[t]];
			st.erase(st.begin());
		}
	}
	cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...