# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
536173 | timreizin | Garage (IOI09_garage) | C++17 | 2 ms | 256 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 <vector>
#include <queue>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<int> r(n), w(m);
for (int &i : r) cin >> i;
for (int &i : w) cin >> i;
vector<int> slots(n);
int res = 0;
queue<int> q;
for (int i = 0; i < 2 * m; ++i)
{
int c;
cin >> c;
if (c > 0)
{
bool place = false;
for (int j = 0; j < n; ++j)
{
if (slots[j] == 0)
{
res += w[c - 1] * r[j];
slots[j] = c;
place = true;
break;
}
}
if (!place) q.push(c);
}
else
{
for (int j = 0; j < n; ++j)
{
if (slots[j] == -c)
{
if (!q.empty())
{
slots[j] = q.front();
q.pop();
res += w[slots[j] - 1] * r[j];
}
else slots[j] = 0;
break;
}
}
}
}
cout << res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |