Submission #235317

#TimeUsernameProblemLanguageResultExecution timeMemory
235317PbezzGarage (IOI09_garage)C++14
100 / 100
7 ms384 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define INF 10000000 #define MAXN 100005 typedef pair<int, int> pii; int main(){ ll int n,m,k,i,j,ans=0; cin>>n>>m; vector<ll int>cost(n); vector<ll int>weight(m); for(i=0;i<n;i++){ cin>>cost[i]; } for(i=0;i<m;i++){ cin>>weight[i]; } queue<ll int>q; int location[m];//localização do carro i int occupied[n];//que carro está em i memset(location, -1, sizeof(location) ); memset(occupied, -1, sizeof(occupied) ); for(j=0;j<2*m;j++){ cin>>k; if(k>0){k--; q.push(k); }else{k++; occupied[location[-k]]=-1; location[-k]=-1; } i=0; while(!q.empty() && i<n){ while(i<n && occupied[i]!=-1)i++; if(i==n)continue; k=q.front(); q.pop(); occupied[i]=k; location[k]=i; ans+=weight[k]*cost[i]; } //cout<<k<<" "<<ans<<endl; } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...