제출 #515765

#제출 시각아이디문제언어결과실행 시간메모리
515765Drew_Garage (IOI09_garage)C++17
100 / 100
1 ms372 KiB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;

ld const PI = 4*atan((ld)1);
const int MAX = 2007;

ll price[MAX];
ll car[MAX];
ll loc[MAX];

set<int> blank;

int main()
{
	fastio;

	int n, m;
	cin >> n >> m;

	for (int i = 1; i <= n; ++i)
		cin >> price[i], blank.insert(i);

	for (int i = 1; i <= m; ++i)
		cin >> car[i];

	queue<int> q;
	ll res = 0;
	for (int i = 0; i < 2*m; ++i)
	{
		int val;
		cin >> val;

		if (val < 0)
		{
			blank.insert(loc[-val]);
			if (!q.empty())
			{
				int tmp = q.front();
				q.pop();

				loc[tmp] = *blank.begin();
				res += car[tmp] * price[loc[tmp]];
				blank.erase(blank.begin());
			}
		}
		else
		{
			if (blank.empty())
				q.push(val);
			else
			{
				loc[val] = *blank.begin();
				res += car[val] * price[loc[val]];
				blank.erase(blank.begin());
			}
		}
	}

	cout << res << '\n';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...