# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
931261 | thisisadarsh | Garage (IOI09_garage) | C++14 | 2 ms | 600 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |