Submission #931261

#TimeUsernameProblemLanguageResultExecution timeMemory
931261thisisadarshGarage (IOI09_garage)C++14
100 / 100
2 ms600 KiB
#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 timeMemoryGrader output
Fetching results...