# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
752466 | wenqi | Garage (IOI09_garage) | C++17 | 2 ms | 348 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.
// trans rights
#include <bits/extc++.h>
using namespace std;
using ll = long long;
#ifdef DEBUG
#define D(args...) fprintf(stderr, args)
#else
#define D(...)
#endif
int N, M;
int rate[105], weight[2005];
int spot[105];
int own[2005];
int main(int argc, const char *argv[])
{
scanf(" %d %d", &N, &M);
for (int i = 1; i <= N; i++)
scanf(" %d", &rate[i]);
for (int i = 1; i <= M; i++)
scanf(" %d", &weight[i]);
int sum = 0;
queue<int> h;
for (int k = 0; k < 2 * M; k++)
{
int x;
scanf(" %d", &x);
if (x > 0)
{
int q = -1;
for (int i = 1; i <= N; i++)
{
if (spot[i] == 0)
{
q = i;
break;
}
}
if (q == -1)
{
h.push(x);
}
else
{
spot[q] = x;
sum += weight[x] * rate[q];
own[x] = q;
}
}
else
{
x = -x;
spot[own[x]] = 0;
if (h.size())
{
int p = h.front();
h.pop();
own[p] = own[x];
spot[own[x]] = p;
sum += weight[p] * rate[own[p]];
}
}
}
printf("%d", sum);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |