Submission #100772

#TimeUsernameProblemLanguageResultExecution timeMemory
100772Alexa2001Garage (IOI09_garage)C++17
100 / 100
5 ms412 KiB
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 1e4 + 5;

int n, m, x, i;
queue<int> q;
priority_queue< int, vector<int>, greater<int> > heap;
int coef[Nmax], w[Nmax], where[Nmax];
long long ans = 0;

int main()
{
   // freopen("input", "r", stdin);

    cin >> n >> m;
    for(i=1; i<=n; ++i) cin >> coef[i];
    for(i=1; i<=m; ++i) cin >> w[i];

    for(i=1; i<=n; ++i) heap.push(i);

    for(i=1; i<=2*m; ++i)
    {
        cin >> x;

        if(x > 0) q.push(x);
            else heap.push(where[-x]);

        while(q.size() && heap.size())
        {
            x = q.front();
            where[x] = heap.top();
            ans += w[x] * coef[where[x]];
            q.pop(); heap.pop();
        }
    }

    cout << ans << '\n';

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