# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
57524 | Bodo171 | Garage (IOI09_garage) | C++14 | 6 ms | 788 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 <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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |