Submission #546363

# Submission time Handle Problem Language Result Execution time Memory
546363 2022-04-07T11:22:27 Z blue Hotel (CEOI11_hot) C++17
100 / 100
1082 ms 63096 KB
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
#define sz(x) int(x.size())

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

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

	multiset<pll> rooms; //(capacity, upkeep)

	for(int i = 1; i <= n; i++)
	{
		ll c, p;
		cin >> c >> p;

		rooms.insert({p, c});
	}

	vector<pll> offers(m); //(capacity requirement = first, gain = second)
	for(int j = 0; j < m; j++)
	{
		cin >> offers[j].second >> offers[j].first;
	}

	sort(offers.begin(), offers.end(), [] (pll U, pll V)
	{
		return U.second > V.second;
	});

	ll res = 0;

	vector<ll> options;



	for(pll z : offers)
	{
		// cerr << "offer = " << z.first << ' ' << z.second << '\n';

		ll capreq = z.first;
		ll gain = z.second;

		auto f = rooms.lower_bound({capreq, -1});

		if(f == rooms.end()) continue;

		if(gain > f->second)
		{
			options.push_back(gain - f->second);
		}
		
		rooms.erase(f);
	}

	sort(options.begin(), options.end());

	for(int i = sz(options)-1; i >= 0 && i >= sz(options)-o; i--)
		res += options[i];

	cout << res << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 4204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 6756 KB Output is correct
2 Correct 74 ms 6272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 270 ms 18560 KB Output is correct
2 Correct 129 ms 11288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 686 ms 35996 KB Output is correct
2 Correct 861 ms 47048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 785 ms 43820 KB Output is correct
2 Correct 882 ms 63096 KB Output is correct
3 Correct 1082 ms 59996 KB Output is correct