# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
752918 | rahidilbayramli | Garage (IOI09_garage) | C++17 | 3 ms | 352 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>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pb push_back
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
using namespace std;
int main()
{
ll n, m, i, j, x, sum = 0;
cin >> n >> m;
ll rate[n+1], weight[m+1], spot[n+1], own[m+1];
memset(spot, 0, sizeof(spot));
memset(own, 0, sizeof(own));
for(i = 1; i <= n; i++) cin >> rate[i];
for(i = 1; i <= m; i++) cin >> weight[i];
queue<ll>h;
for(j = 1; j <= 2 * m; j++)
{
cin >> x;
if(x > 0)
{
ll q = -1;
for(i = 1; i <= n; i++)
{
if(spot[i] == 0)
{
q = i;
break;
}
}
if(q == -1)
h.push(x);
else
{
spot[q] = x;
sum += rate[q] * weight[x];
own[x] = q;
}
}
else
{
x = -x;
spot[own[x]] = 0;
if(h.size())
{
ll p = h.front();
own[p] = own[x];
h.pop();
spot[own[x]] = p;
sum += weight[p] * rate[own[p]];
}
}
}
cout << sum << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |