# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
858692 | aykhn | Garage (IOI09_garage) | C++14 | 1 ms | 456 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |