# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
114321 | MetB | Garage (IOI09_garage) | C++14 | 3 ms | 512 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 <cstdlib>
#include <string>
#include <set>
#include <stdio.h>
#include <map>
#include <algorithm>
#include <bitset>
#include <queue>
#include <math.h>
#include <stack>
#include <vector>
#include <string.h>
typedef long long ll;
const ll MOD = 1e9 + 7, INF = 1e18;
using namespace std;
ll n, k, a[1000000], m, off[1000000];
vector <ll> v;
ll u[100], s[100], w[5000], p[5000], ans;
queue <ll> waiting;
int main ()
{
cin >> n >> m;
for (ll i = 0; i < n; i++)
scanf ("%lld", &s[i]);
for (ll i = 0; i < m; i++)
scanf ("%lld", &w[i]);
for (ll i = 0; i < 2 * m; i++)
{
ll t;
scanf ("%lld", &t);
if (t >= 0)
{
t--;
bool b = false;
for (ll j = 0; j < n; j++)
{
if (!u[j])
{
p[t] = j;
ans += s[j] * w[t];
u[j] = 1;
b = true;
break;
}
}
if (!b) waiting.push (t);
}
else
{
t = abs (t) - 1;
off[t] = 1;
u[p[t]] = 0;
while (!waiting.empty () && off[waiting.front ()]) waiting.pop ();
if (!waiting.empty ())
{
u[p[t]] = 1;
p[waiting.front ()] = p[t];
ans += s[p[t]] * w[waiting.front ()];
waiting.pop ();
}
}
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |