Submission #57524

#TimeUsernameProblemLanguageResultExecution timeMemory
57524Bodo171Garage (IOI09_garage)C++14
100 / 100
6 ms788 KiB
#include <iostream> #include <fstream> using namespace std; const int nmax=2005; int r[nmax],w[nmax],loc[nmax],lib[nmax],q[nmax]; int n,m,i,j,ind,p,u,x; long long ans; int main() { //freopen("data.in","r",stdin); cin>>n>>m; for(i=1;i<=n;i++) { cin>>r[i]; lib[i]=1; } for(i=1;i<=m;i++) { cin>>w[i]; } p=1; for(i=1;i<=2*m;i++) { cin>>x; if(x>0) { ind=1; while(ind<=n&&(!lib[ind])) ind++; if(ind==n+1) q[++u]=x; else lib[ind]=0,ans+=1LL*r[ind]*w[x],loc[x]=ind; } else { x*=(-1); lib[loc[x]]=1; if(p<=u) { loc[q[p]]=loc[x]; lib[loc[x]]=0; ans+=1LL*r[loc[x]]*w[q[p]]; p++; } } } cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...