Submission #931261

# Submission time Handle Problem Language Result Execution time Memory
931261 2024-02-21T13:23:58 Z thisisadarsh Garage (IOI09_garage) C++14
100 / 100
2 ms 600 KB
	#include <bits/stdc++.h>
using namespace std;

int main(){
	int N,M;
	cin >> N >> M;
	vector<pair<int, bool>> a(N+1);
	for(int i = 1; i < N+1; i++){
		cin >> a[i].first;
		a[i].second = false;
	}
	vector<pair<int, int>> cars(M+1);
	for(int i = 1; i < M+1; i++){
		cin >> cars[i].first;
		cars[i].second = 0;
	}
	vector<int> queue;
	int total_cost = 0;
	int q = 2 * M;
	while(q--){
		int come;
		cin >> come;
		if(come > 0){
			int empty = 0;
			for(int i = 1; i < N+1; i++){
				if(a[i].second == false){
					empty = i;
					break;
				}
			}
			if(empty == 0){
				queue.push_back(come);
			}
			else{
				total_cost += a[empty].first * cars[come].first;
				a[empty].second = true, cars[come].second = empty;
			}
		}
		else{
			come *= -1;
			int to_remove = cars[come].second;
			cars[come].second = 0;
			a[to_remove].second = false;
			if(queue.size() > 0){
				cars[queue[0]].second = to_remove;
				total_cost += a[to_remove].first * cars[queue[0]].first;
				a[to_remove].second = true;
				queue.erase(queue.begin());
			}
		}
	}
	cout << total_cost << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 2 ms 348 KB Output is correct