Submission #309190

#TimeUsernameProblemLanguageResultExecution timeMemory
309190TemmieGarage (IOI09_garage)C++17
100 / 100
2 ms384 KiB
#include <bits/stdc++.h>

int main() {
	std::ios::sync_with_stdio(0); std::cin.tie(0);
	int n, m; std::cin >> n >> m;
	std::vector <int> r(n);
	for (int& x : r) std::cin >> x;
	std::vector <int> w(m);
	for (int& x : w) std::cin >> x;
	std::vector <int> park(n, 0);
	int ans = 0;
	std::queue <int> q;
	for (int i = 0; i < m << 1; i++) {
		int p; std::cin >> p;
		if (p > 0) {
			q.push(p);
		} else {
			for (int j = 0; j < n; j++) {
				if (park[j] == -p) park[j] = 0;
			}
		}
		while (q.size()) {
			bool ok = false;
			int now = q.front();
			for (int j = 0; j < n; j++) {
				if (!park[j]) {
					ok = true;
					park[j] = now;
					q.pop();
					ans += w[now - 1] * r[j];
					break;
				}
			}
			if (!ok) break;
		}
	}
	std::cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...