제출 #957523

#제출 시각아이디문제언어결과실행 시간메모리
957523hirayuu_ojGarage (IOI09_garage)C++17
100 / 100
1 ms600 KiB
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,l,r) for(int i=(l); i<(r); i++)
#define all(x) x.begin(),x.end()
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,M;
    cin>>N>>M;
    vector<ll> R(N);
    rep(i,N){
        cin>>R[i];
    }
    vector<ll> W(M);
    rep(i,M){
        cin>>W[i];
    }
    vector<ll> use(N,-1);
    queue<ll> wait;
    ll ans=0;
    rep(i,2*M){
        ll t;
        cin>>t;
        if(t>0){
            t--;
            rep(j,N){
                if(use[j]==-1){
                    use[j]=t;
                    ans+=W[t]*R[j];
                    t=-1;
                    break;
                }
            }
            if(t!=-1){
                wait.push(t);
            }
        }
        else{
            t=-1-t;
            rep(j,N){
                if(use[j]==t){
                    use[j]=-1;
                    if(!wait.empty()){
                        use[j]=wait.front();
                        ans+=W[wait.front()]*R[j];
                        wait.pop();
                    }
                    break;
                }
            }
        }
    }
    cout<<ans<<"\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...