# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
76072 | luciocf | Garage (IOI09_garage) | C++14 | 5 ms | 1268 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.
// IOI 2009 - Garage
// Lúcio Cardoso
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110;
const int MAXM = 2010;
int num[MAXM], peso[MAXM], custo[MAXN];
bool ocupado[MAXN];
int main(void)
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> custo[i];
for (int i = 1; i <= m; i++)
cin >> peso[i];
queue<int> fila;
int ans = 0;
for (int i = 1; i <= 2*m; i++)
{
int x;
cin >> x;
if (x > 0)
{
bool flag = 0;
for (int i = 1; i <= n; i++)
{
if (!ocupado[i])
{
ocupado[i] = 1;
flag = 1;
ans += peso[x]*custo[i];
num[x] = i;
break;
}
}
if (!flag) fila.push(x);
}
else
{
x = -x;
ocupado[num[x]] = 0;
if (fila.size() > 0)
{
num[fila.front()] = num[x];
ans += custo[num[x]]*peso[fila.front()];
fila.pop();
ocupado[num[x]] = 1;
}
}
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |