Submission #1225033

#TimeUsernameProblemLanguageResultExecution timeMemory
1225033lukasuliashviliGarage (IOI09_garage)C++20
100 / 100
1 ms328 KiB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 105;
const int MAXM = 2005;

int n, m;
int rate[MAXN];  
int weight[MAXM]; 
int parking[MAXN]; 
queue<int> waitQueue;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> rate[i];
    for (int i = 0; i < m; i++) cin >> weight[i];

    int totalEvents = 2 * m;
    vector<int> events(totalEvents);
    for (int i = 0; i < totalEvents; i++) {
        cin >> events[i];
    }

    int totalRevenue = 0;

    for (int e : events) {
        if (e > 0) {
            
            int car = e - 1;
            bool parked = false;
            for (int i = 0; i < n; i++) {
                if (parking[i] == 0) {
                    parking[i] = car + 1;
                    totalRevenue += rate[i] * weight[car];
                    parked = true;
                    break;
                }
            }
            if (!parked) waitQueue.push(car);
        } else {
            
            int car = -e - 1;
            int spot = -1;
            for (int i = 0; i < n; i++) {
                if (parking[i] == car + 1) {
                    spot = i;
                    break;
                }
            }
            parking[spot] = 0;

            if (!waitQueue.empty()) {
                int nextCar = waitQueue.front();
                waitQueue.pop();
                parking[spot] = nextCar + 1;
                totalRevenue += rate[spot] * weight[nextCar];
            }
        }
    }

    cout << totalRevenue << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...