제출 #443673

#제출 시각아이디문제언어결과실행 시간메모리
443673BelguteiGarage (IOI09_garage)C++17
100 / 100
4 ms460 KiB
#include<bits/stdc++.h>

using namespace std;

#define ll long long 
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

queue<int> q;
ll n,m,cost[105],weight[2005];
bool used[105];
ll ans;
map<ll,ll> mp;
map<ll,ll> :: iterator it;

int main(){
    cin>>n>>m;
    for(int i=1; i<=n; i++){
        cin>>cost[i];
    }
    for(int i=1; i<=m; i++){
        cin>>weight[i];
    }
    for(int i=1; i<=2*m; i++){
        ll num;
        cin>>num;
        if(num<0){
            num=-num;
            if(q.size()>0){
                ll val=q.front();
                q.pop();
                ans+=weight[val]*cost[mp[num]];
                mp[val]=mp[num];
            }
            else{
                used[mp[num]]=0;
            }
            continue;
        }
        bool check=0;
        for(int j=1; j<=n; j++){
            if(used[j]==0){
                used[j]=1;
                check=1;
                ans+=cost[j]*weight[num];
                mp[num]=j;
                break;
            }
        }
        if(check==0) q.push(num);
    }
    cout<<ans<<'\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...