Submission #697750

#TimeUsernameProblemLanguageResultExecution timeMemory
697750hiikunZGarage (IOI09_garage)C++17
100 / 100
2 ms340 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> R(N),W(M),U(N,0),P(M,-1);
    ll ans = 0;
    for(ll i = 0;i < N;i++) cin >> R[i];
    for(ll i = 0;i < M;i++) cin >> W[i];
    queue<ll> que;
    for(ll q = 0;q < M * 2;q++){
        ll s;
        cin >> s;
        if(s > 0){
            s--;
            que.emplace(s);
        }
        else{
            s *= -1;
            s--;
            U[P[s]] = 0;
        }
        while(!que.empty()){
            ll ok = 0;
            for(ll i = 0;i < N;i++){
                if(U[i] == 0){
                    U[i] = 1;
                    P[que.front()] = i;
                    ans += R[i] * W[que.front()];
                    que.pop();
                    ok = 1;
                    break;
                }
            }
            if(!ok) break;
        }
    }
    cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...