Submission #79870

# Submission time Handle Problem Language Result Execution time Memory
79870 2018-10-17T02:57:53 Z shoemakerjo Garage (IOI09_garage) C++14
100 / 100
3 ms 1088 KB
#include <bits/stdc++.h>

using namespace std;
#define pii pair<int, int>

int N, M;
int rate[105];
int weight[10010];
int myspot[10010];

set<pii> curout;
set<int> openspots;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		cin >> rate[i];
		openspots.insert(i);
	}
	for (int i = 1; i <= M; i++) {
		cin >> weight[i];
	}
	int ct = 0;
	int ans = 0;

	int cur;
	for (int i = 0; i < 2*M; i++) {
		cin >> cur;
		if (cur < 0) {
			cur *= -1;
			// openspots.insert(myspot[cur]);
			if (curout.size()) {
				pii val = *curout.begin();
				curout.erase(curout.begin());
				ans += weight[val.second] * rate[myspot[cur]];
				myspot[val.second] = myspot[cur];
			}
			else openspots.insert(myspot[cur]);

		}
		else {
			if (openspots.size()) {

				ans += weight[cur] * (rate[*openspots.begin()]);
				myspot[cur] = *openspots.begin();
				openspots.erase(openspots.begin());

			}
			else curout.insert(pii(++ct, cur));

		}
	}

	// for (int i = 1; i <= M; i++) {
	// 	cout << i << " went to spot " << myspot[i] << endl;
	// }


	cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 584 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 2 ms 664 KB Output is correct
7 Correct 2 ms 808 KB Output is correct
8 Correct 2 ms 808 KB Output is correct
9 Correct 2 ms 808 KB Output is correct
10 Correct 2 ms 880 KB Output is correct
11 Correct 2 ms 880 KB Output is correct
12 Correct 2 ms 880 KB Output is correct
13 Correct 2 ms 880 KB Output is correct
14 Correct 2 ms 880 KB Output is correct
15 Correct 2 ms 880 KB Output is correct
16 Correct 3 ms 880 KB Output is correct
17 Correct 3 ms 892 KB Output is correct
18 Correct 3 ms 932 KB Output is correct
19 Correct 3 ms 1088 KB Output is correct
20 Correct 3 ms 1088 KB Output is correct