Submission #1323360

#TimeUsernameProblemLanguageResultExecution timeMemory
1323360hectormedranoGarage (IOI09_garage)C++20
100 / 100
1 ms412 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    ll N, M, x, ans;
    cin>>N>>M;
    ans = 0;
    vector<ll> R(N), W(M), p(M);
    set<ll> d;
    queue<ll> q;
    for(ll i=0;i<N;i++){
        cin>>R[i];
        d.insert(i);
    }
    for(ll i=0;i<M;i++){cin>>W[i];}
    for(ll i=0;i<2*M;i++){
        cin>>x;
        if(x > 0){
            x--;
            q.push(x);
        } else {
            x = (-x-1);
            d.insert(p[x]);
        }
        if(q.size() == 0 or d.size() == 0){continue;}
        ll e = *(d.begin());
        ll c = q.front();
        p[c] = e;
        ans += W[c]*R[e];
        q.pop();
        d.erase(e);
    }
    cout<<ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...