Submission #733884

#TimeUsernameProblemLanguageResultExecution timeMemory
733884vjudge1Garage (IOI09_garage)C++17
100 / 100
2 ms340 KiB
#include<bits/stdc++.h>
using namespace std;

int ans, a[101], b[2001], n, m, x, vis[2001];
set<int> s;
set<int>::iterator it;
vector<int> v;

int main() {
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		s.insert(i);
	}
	for(int i = 1; i <= m; i++) {
		cin >> b[i];
	}
	for(int i = 1; i <= m * 2; i++) {
		cin >> x;
		if(x < 0) {
			s.insert(vis[x * -1]);
			if(v.size() != 0) {
				it = s.begin();
				vis[v[0]] = *it;
				ans += a[*it] * b[v[0]];
				s.erase(it);
				v.erase(v.begin());
			}
		}
		else {
			v.push_back(x);
			if(s.size() != 0){
				it = s.begin();
				vis[v[0]] = *it;
				ans += a[*it] * b[v[0]];
//				cout << a[*it] << ' ' << b[v[0]] << '\n';
				s.erase(it);
				v.erase(v.begin());
			}
		}
	}
	cout << ans;
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...