# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
228447 | s_avila_g | Garage (IOI09_garage) | C++14 | 9 ms | 640 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
queue<long long> col;
map<long long,long long> mp;
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
long long n,m;
cin>>n>>m;
vector<long long> parks(n);
vector<long long> cars(n);
for(long long i = 0 ; i < n; i++)cin>>parks[i];
for(long long i = 0 ; i < m; i++)cin>>cars[i];
long long vis[n];
memset(vis,0,sizeof vis);
long long ans = 0;
for(long long i = 0 ; i < (2*m); i++){
long long x;
cin>>x;
bool libre = false;
if(x > 0){
long long pos;
for(long long j = 0; j < n; j++){
if(vis[j] == 0){
libre = true;
pos = j;
break;
}
}
if(!libre){
col.push(x);
}else{
mp[x] = pos;
ans += cars[x-1] * parks[pos];
vis[pos] = 1;
}
}else{
vis[mp[abs(x)]] = 0;
if(!col.empty()){
long long nxt = col.front();
vis[mp[abs(x)]] = 1;
col.pop();
ans += cars[nxt-1] * parks[mp[abs(x)]];
}
mp[abs(x)] = -1;
}
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |