제출 #1348784

#제출 시각아이디문제언어결과실행 시간메모리
1348784SSKMFGarage (IOI09_garage)C++20
100 / 100
0 ms344 KiB
#include <bits/stdc++.h>
using namespace std;

queue <int> coada;
int factor_1[101] , factor_2[2001] , locatie[2001];
set <int> liber;

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

    int numar_optiuni , numar_operatii;
    cin >> numar_optiuni >> numar_operatii;

    for (int indice = 1 ; indice <= numar_optiuni ; indice++)
        { cin >> factor_1[indice]; liber.insert(indice); }
    for (int indice = 1 ; indice <= numar_operatii ; indice++)
        { cin >> factor_2[indice]; }

    int64_t cost = 0;
    for (int indice = 1 ; indice <= 2 * numar_operatii ; indice++)
    {
        int tip;
        cin >> tip;

        if (tip < 0)
        { 
            if (coada.empty())
                { liber.insert(locatie[-tip]); }
            else
            {
                const int __indice = coada.front();
                coada.pop();

                cost += 1LL * factor_1[locatie[-tip]] * factor_2[__indice];
                locatie[__indice] = locatie[-tip];
            }
        }
        else
        {
            if (liber.empty())
                { coada.push(tip); }
            else
            {
                const int __indice = *liber.begin();
                liber.erase(liber.begin());

                cost += 1LL * factor_1[__indice] * factor_2[tip];
                locatie[tip] = __indice;
            }
        }
    }

    cout << cost;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...