Submission #1055646

#TimeUsernameProblemLanguageResultExecution timeMemory
1055646BraulinhoGarage (IOI09_garage)C++14
30 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios::sync_with_stdio(0); cin.tie(0); cout.setf(ios::fixed); cout.precision(10); ll N, M; cin >> N >> M; vector<ll> rates(N + 1); vector<ll> weights(M + 1); vector<ll> parking(N + 1, 0); queue<ll> waitingQueue; for (int i = 1; i <= N; ++i) { cin >> rates[i]; } for (int i = 1; i <= M; ++i) { cin >> weights[i]; } stack<ll> freeSpaces; for (int i = N; i >= 1; --i) { freeSpaces.push(i); } ll totalRevenue = 0; for (int i = 0; i < 2 * M; ++i) { int car; cin >> car; if (car > 0) { if (!freeSpaces.empty()) { int space = freeSpaces.top(); freeSpaces.pop(); parking[space] = car; totalRevenue += weights[car] * rates[space]; } else { waitingQueue.push(car); } } else { car = -car; ll space = 0; for (int j = 1; j <= N; ++j) { if (parking[j] == car) { space = j; break; } } parking[space] = 0; freeSpaces.push(space); if (!waitingQueue.empty()) { ll nextCar = waitingQueue.front(); waitingQueue.pop(); freeSpaces.pop(); parking[space] = nextCar; totalRevenue += weights[nextCar] * rates[space]; } } } cout << totalRevenue << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...