Submission #74490

#TimeUsernameProblemLanguageResultExecution timeMemory
74490JustInCaseGarage (IOI09_garage)C++17
100 / 100
4 ms856 KiB
#include <bits/stdc++.h> #define endl '\n' using namespace std; const int32_t MAX_N = 100; const int32_t MAX_M = 2000; int32_t rates[MAX_N + 5], weights[MAX_M + 5], placeOf[MAX_M + 5]; set< int32_t > emptyPlaces; queue< int32_t > waitingCars; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int32_t n, m; cin >> n >> m; for(int32_t i = 0; i < n; i++) { cin >> rates[i]; emptyPlaces.insert(i); } for(int32_t i = 0; i < m; i++) { cin >> weights[i]; } int32_t ans = 0; for(int32_t i = 0; i < 2 * m; i++) { int32_t ind; cin >> ind; if(ind < 0) { ind = -ind; emptyPlaces.insert(placeOf[ind]); if(!waitingCars.empty()) { int32_t ind = waitingCars.front(); waitingCars.pop(); placeOf[ind] = *emptyPlaces.begin(); emptyPlaces.erase(emptyPlaces.begin()); ans += rates[placeOf[ind]] * weights[ind - 1]; } } else { if(!emptyPlaces.empty()) { placeOf[ind] = *emptyPlaces.begin(); emptyPlaces.erase(emptyPlaces.begin()); ans += rates[placeOf[ind]] * weights[ind - 1]; } else { waitingCars.push(ind); } } } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...