# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
54673 | okaybody10 | Garage (IOI09_garage) | C++98 | 4 ms | 844 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>
typedef long long ll;
using namespace std;
queue<int> wait;
priority_queue<int> parking;
int cost[1006],car[10007],weight[10006];
int main()
{
int N,M; scanf("%d %d",&N,&M);
ll ans=0;
for(int i=1;i<=N;i++) parking.push(-i);
for(int i=1;i<=N;i++) scanf("%d",&cost[i]);
for(int i=1;i<=M;i++) scanf("%d",&weight[i]);
for(int i=0;i<2*M;i++)
{
int t; scanf("%d",&t);
if(t<0) parking.push(-car[-t]);
else
{
if(parking.size()==0) wait.push(t);
else
{
int v=-parking.top();
parking.pop();
car[t]=v; ans+=weight[t]*cost[v];
}
}
while(!wait.empty() && !parking.empty())
{
int c1=wait.front(); wait.pop();
int c2=-parking.top(); parking.pop();
car[c1]=c2; ans+=cost[c2]*weight[c1];
}
}
return !printf("%lld",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |