Submission #715369

#TimeUsernameProblemLanguageResultExecution timeMemory
715369ToxtaqGarage (IOI09_garage)C++17
100 / 100
3 ms340 KiB
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int spaces, cars;
    long long result = 0;
    cin >> spaces >> cars;
    vector<int>rate(spaces + 1), weights(cars + 1);
    for(int i = 1;i <= spaces;++i)cin >> rate[i];
    for(int i = 1;i <= cars;++i)cin >> weights[i];
    vector<int>parking(spaces + 1);
    queue<int>q;
    for(int i = 0;i < 2 * cars;++i){
        int car;
        bool parked = false;
        cin >> car;
        if(car > 0){
            for(int j = 1;j <= spaces;++j){
                if(!parking[j]){
                    parking[j] = car;
                    result += weights[car] * rate[j];
                    parked = true;
                    break;
                }
            }
            if(!parked){
                q.push(car);
            }
        }
        else{
            for(int j = 1;j <= spaces;++j){
                if(-car == parking[j]){
                    parking[j] = 0;
                    break;
                }
            }
            if(!q.empty()){
                int cur = q.front();
                q.pop();
                for(int j = 1;j <= spaces;++j){
                    if(!parking[j]){
                        parking[j] = cur;
                        result += weights[cur] * rate[j];
                        break;
                    }
                }
            }
        }
    }
    cout << result;
}
#Verdict Execution timeMemoryGrader output
Fetching results...