799B - T-shirt buying - CodeForces Solution


data structures implementation *1400

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <utility>

#define ll long long
#define MOD 1000000007

using namespace std;

void solve()
{
	int n; cin >> n;
	vector<int> p(n), a(n), b(n);
	for (int i = 0; i < n; i++)	cin >> p[i];
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];

	int m; cin >> m;
	vector<int> c(m);
	for (int i = 0; i < m; i++) cin >> c[i];

	set<int> r, g, d;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == 1 || b[i] == 1) r.insert(p[i]);
		if (a[i] == 2 || b[i] == 2) g.insert(p[i]);
		if (a[i] == 3 || b[i] == 3) d.insert(p[i]);
	}

	for (auto el : c)
	{
		int price;
		if (el == 1 && r.size())
			price = *r.begin();
		else if (el == 2 && g.size())
			price = *g.begin();
		else if (el == 3 && d.size())
			price = *d.begin();
		else
			price = -1;
		cout << price << " ";
		r.erase(price);
		g.erase(price);
		d.erase(price);
	}

}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); //file input.txt is opened in reading mode i.e "r"
	freopen("output.txt", "w", stdout); //file output.txt is opened in writing mode i.e "w"
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int tc = 1;
	// cin >> tc;
	while (tc--)
		solve();
	return 0;
}



Comments

Submit
0 Comments
More Questions

1472C - Long Jumps
1293D - Aroma's Search
918A - Eleven
1237A - Balanced Rating Changes
1616A - Integer Diversity
1627B - Not Sitting
1663C - Pōja Verdon
1497A - Meximization
1633B - Minority
688B - Lovely Palindromes
66B - Petya and Countryside
1557B - Moamen and k-subarrays
540A - Combination Lock
1553C - Penalty
1474E - What Is It
1335B - Construct the String
1004B - Sonya and Exhibition
1397A - Juggling Letters
985C - Liebig's Barrels
115A - Party
746B - Decoding
1424G - Years
1663A - Who Tested
1073B - Vasya and Books
195B - After Training
455A - Boredom
1099A - Snowball
1651D - Nearest Excluded Points
599A - Patrick and Shopping
237A - Free Cash