# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
858692 | aykhn | Garage (IOI09_garage) | C++14 | 1 ms | 456 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>
// author : aykhn
using namespace std;
typedef long long ll;
#define pb push_back
#define ins insert
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define bpc __builtin_popcount
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define int ll
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F
const int MXN = 1e4 + 5;
int n, m;
int r[MXN], w[MXN], id[MXN];
queue<int> q;
set<int> s;
int res;
void _()
{
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> r[i];
for (int i = 1; i <= m; i++) cin >> w[i];
for (int i = 1; i <= n; i++) s.ins(i);
for (int i = 1; i <= 2*m; i++)
{
int x;
cin >> x;
if (x < 0)
{
if (q.empty())
{
s.ins(id[-x]);
continue;
}
int y = q.front();
q.pop();
id[y] = id[-x];
id[-x] = 0;
res += r[id[y]] * w[y];
continue;
}
if (s.empty())
{
q.push(x);
continue;
}
id[x] = *s.begin();
s.erase(s.begin());
res += r[id[x]] * w[x];
}
cout << res << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
for (int i = 1; i <= t; i++)
{
_();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |