Submission #752918

#TimeUsernameProblemLanguageResultExecution timeMemory
752918rahidilbayramliGarage (IOI09_garage)C++17
100 / 100
3 ms352 KiB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pb push_back
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
using namespace std;
int main()
{
    ll n, m, i, j, x, sum = 0;
    cin >> n >> m;
    ll rate[n+1], weight[m+1], spot[n+1], own[m+1];
    memset(spot, 0, sizeof(spot));
    memset(own, 0, sizeof(own));
    for(i = 1; i <= n; i++)    cin >> rate[i];
    for(i = 1; i <= m; i++)    cin >> weight[i];
    queue<ll>h;
    for(j = 1; j <= 2 * m; j++)
    {
        cin >> x;
        if(x > 0)
        {
            ll q = -1;
            for(i = 1; i <= n; i++)
            {
                if(spot[i] == 0)
                {
                    q = i;
                    break;
                }
            }
            if(q == -1)
                h.push(x);
            else
            {
                spot[q] = x;
                sum += rate[q] * weight[x];
                own[x] = q;
            }
        }
        else
        {
            x = -x;
            spot[own[x]] = 0;
            if(h.size())
            {
                ll p = h.front();
                own[p] = own[x];
                h.pop();
                spot[own[x]] = p;
                sum += weight[p] * rate[own[p]];
            }
        }
    }
    cout << sum << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...