Submission #986728

#TimeUsernameProblemLanguageResultExecution timeMemory
986728lyuGarage (IOI09_garage)C++17
100 / 100
2 ms500 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; int parking[n]; for(int i = 0; i < n; i++) cin >> parking[i]; int weight[m]; for(int i = 0; i < m; i++) cin >> weight[i]; int status, profit = 0; unordered_map<int, int> cars; unordered_map<int, int> taken; queue<int> waiting; for(int i = 0; i < 2*m; i++) { cin >> status; if(status > 0) { status--; bool parked = false; for(int i = 0; i < n; i++) { if(taken.count(i) == 0) { taken[i] = status; cars[status] = i; profit += parking[i] * weight[status]; parked = true; break; } } if(!parked) waiting.push(status); } else { status++; status *= -1; int num = cars[status]; cars.erase(status); taken.erase(num); if(!waiting.empty()) { int f = waiting.front(); cars[f] = num; taken[num] = f; profit += weight[f] * parking[num]; waiting.pop(); } } } cout << profit << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...