Submission #443673

# Submission time Handle Problem Language Result Execution time Memory
443673 2021-07-11T08:58:45 Z Belgutei Garage (IOI09_garage) C++17
100 / 100
4 ms 460 KB
#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 time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 4 ms 460 KB Output is correct
20 Correct 3 ms 460 KB Output is correct