제출 #1055644

#제출 시각아이디문제언어결과실행 시간메모리
1055644BraulinhoGarage (IOI09_garage)C++14
30 / 100
1 ms456 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);

    int N, M;
    cin >> N >> M;

    vector<int> rates(N + 1);
    vector<int> weights(M + 1);
    vector<int> parking(N + 1, 0);
    queue<int> waitingQueue;

    for (int i = 1; i <= N; ++i) {
        cin >> rates[i];
    }

    for (int i = 1; i <= M; ++i) {
        cin >> weights[i];
    }

    stack<int> freeSpaces;
    for (int i = N; i >= 1; --i) {
        freeSpaces.push(i);
    }

    int 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;
            int 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()) {
                int 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...