Submission #1082754

#TimeUsernameProblemLanguageResultExecution timeMemory
1082754toast12Garage (IOI09_garage)C++14
100 / 100
4 ms456 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> rates(n), weights(m); for (int i = 0; i < n; i++) { cin >> rates[i]; } for (int i = 0; i < m; i++) { cin >> weights[i]; } multiset<int> available; for (int i = 0; i < n; i++) { available.insert(i); } map<int, int> lots; queue<int> q; long long ans = 0; for (int i = 0; i < 2*m; i++) { int car; cin >> car; if (car < 0) { car *= -1; car--; if (!q.empty()) { int car2 = q.front(); lots[car2] = lots[car]; ans += weights[car2]*rates[lots[car2]]; q.pop(); } else { available.insert(lots[car]); } lots[car] = 0; continue; } car--; if (available.empty()) { q.push(car); continue; } int lot = *(available.begin()); ans += weights[car]*rates[lot]; lots[car] = lot; available.erase(lot); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...