Submission #420780

# Submission time Handle Problem Language Result Execution time Memory
420780 2021-06-08T13:53:02 Z chirathnirodha Garage (IOI09_garage) C++17
100 / 100
2 ms 332 KB
//Coded by Chirath Nirodha
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define I insert
#define P push
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_tree;
const ll mod=1e9+7;
inline void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
void solve(){
    io();
    int n,m;cin>>n>>m;
    int r[n],w[m];
    for(int i=0;i<n;i++)cin>>r[i];
    for(int i=0;i<m;i++)cin>>w[i];
    bool park[n];memset(park,false,sizeof(park));
    int place[m];
    ll ans=0;
    queue<int> q;
    for(int i=0;i<2*m;i++){
        int x;cin>>x;
        if(x>0){
            x--;
            bool found=false;
            for(int j=0;j<n;j++)
                if(!park[j]){
                    park[j]=true;
                    place[x]=j;
                    ans+=w[x]*r[j];
                    found=true;
                    break;
                }
            if(!found)q.P(x);  
        } 
        else{
            x++;x*=-1;
            park[place[x]]=false;
            if(!q.empty()){
                int c=q.front();q.pop();
                park[place[x]]=true;
                place[c]=place[x];
                ans+=w[c]*r[place[x]];
            }
        }
    }
    cout<<ans<<endl;
}
int main(){
    io();
    solve();
}
# 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 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 316 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 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct