Submission #758186

# Submission time Handle Problem Language Result Execution time Memory
758186 2023-06-14T08:49:32 Z SanguineChameleon Garage (IOI09_garage) C++17
100 / 100
2 ms 340 KB
#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 time Memory Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct