# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
703382 | finn__ | Garage (IOI09_garage) | C++17 | 2 ms | 340 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>
using namespace std;
int main()
{
size_t n, m;
cin >> n >> m;
queue<unsigned> q_car;
priority_queue<pair<unsigned, unsigned>> q_lot;
for (size_t i = 0; i < n; i++)
{
unsigned s;
cin >> s;
q_lot.emplace(n - i, s);
}
vector<unsigned> weights(m);
vector<pair<unsigned, unsigned>> assigned_lot(m);
for (unsigned &x : weights)
cin >> x;
unsigned revenue = 0;
for (size_t i = 0; i < 2 * m; i++)
{
int j;
cin >> j;
if (j < 0)
{
if (!q_car.empty())
{
assigned_lot[q_car.front()] = assigned_lot[-j - 1];
revenue += weights[q_car.front()] * assigned_lot[-j - 1].second;
q_car.pop();
}
else
{
q_lot.push(assigned_lot[-j - 1]);
}
}
else
{
if (!q_lot.empty())
{
assigned_lot[j - 1] = q_lot.top();
revenue += weights[j - 1] * q_lot.top().second;
q_lot.pop();
}
else
{
q_car.push(j - 1);
}
}
}
cout << revenue << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |