Submission #309190

# Submission time Handle Problem Language Result Execution time Memory
309190 2020-10-02T21:09:04 Z Temmie Garage (IOI09_garage) C++17
100 / 100
2 ms 384 KB
#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 time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct