# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
113162 | joseacaz | Garage (IOI09_garage) | C++17 | 6 ms | 384 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 <queue>
#define MAXN 105
#define MAXM 2005
using namespace std;
typedef long long lld;
int N, M, cost[MAXN], weight[MAXM], car, space[MAXM], aux, ans;
queue < int > Q;
priority_queue < int > PQ;
int main ()
{
cin >> N >> M;
for ( int i = 1; i <= N; i++ )
cin >> cost[i];
for ( int i = 1; i <= M; i++ )
cin >> weight[i];
for ( int i = 1; i <= N; i++ )
PQ.push(-i);
for ( int i = 0; i < 2 * M; i++ )
{
cin >> car;
if ( car < 0 )
{
car = -car;
if ( Q.size () > 0 )
{
aux = space[car];
space[Q.front()] = aux;
ans += (cost[aux] * weight[Q.front()] );
Q.pop();
}
else
{
PQ.push ( -space[car] );
space[car] = 0;
}
}
else if ( car > 0 )
{
if ( PQ.size() > 0 )
{
aux = -PQ.top();
PQ.pop();
space[car] = aux;
ans += (cost[aux] * weight[car]);
}
else
Q.push ( car );
}
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |