제출 #758186

#제출 시각아이디문제언어결과실행 시간메모리
758186SanguineChameleonGarage (IOI09_garage)C++17
100 / 100
2 ms340 KiB
#include <bits/stdc++.h>
using namespace std;

void just_do_it();

int main() {
	#ifdef KAMIRULEZ
		freopen("kamirulez.inp", "r", stdin);
		freopen("kamirulez.out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	just_do_it();
	return 0;
}

const int maxn = 1e2 + 20;
const int maxm = 2e3 + 20;
int rate[maxn];
int weight[maxm];
int cur_id[maxn];

void just_do_it() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> rate[i];
	}
	for (int i = 1; i <= m; i++) {
		cin >> weight[i];
	}
	deque<int> q;
	int res = 0;
	for (int i = 1; i <= m * 2; i++) {
		int id;
		cin >> id;
		if (id < 0) {
			id = -id;
			for (int j = 1; j <= n; j++) {
				if (cur_id[j] == id) {
					cur_id[j] = 0;
					break;
				}
			}
		}
		else {
			q.push_back(id);
		}
		while (!q.empty()) {
			int id = q.front();
			bool found = false;
			for (int j = 1; j <= n; j++) {
				if (cur_id[j] == 0) {
					res += weight[id] * rate[j];
					cur_id[j] = id;
					found = true;
					break;
				}
			}
			if (found) {
				q.pop_front();
			}
			else {
				break;
			}
		}
	}
	cout << res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...