Submission #591975

# Submission time Handle Problem Language Result Execution time Memory
591975 2022-07-08T10:10:58 Z starchan Garage (IOI09_garage) C++17
100 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define MX (int)3e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
signed main()
{
	fast();
	int n, m;
	cin >> n >> m;
	vector<int> r(n+1);
	set<int> empty;
	for(int i = 1; i <= n; i++)
	{
		cin >> r[i];
		empty.insert(i);
	}
	vector<int> which(m+1);
	vector<int> w(m+1);
	for(int i = 1; i <= m; i++)
		cin >> w[i];
	int t = 2*m;
	int ans = 0;
	queue<int> welp;
	while(t--)
	{
		int x;
		cin >> x;
		int u = abs(x);
		if(x > 0)
		{
			if(empty.empty())
			{
				welp.push(x);
				continue;
			}
			int k = *empty.begin();
			which[u] = k;
			empty.erase(empty.begin());
			ans+=(w[u]*r[k]);
		}
		else
		{
			empty.insert(which[u]);
			while(welp.size() && empty.size())
			{
				int u = welp.front();
				welp.pop();
				int k = *empty.begin();
				which[u] = k;
				empty.erase(empty.begin());
				ans+=(w[u]*r[k]);
			}
		}
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct