Skip to content

Instantly share code, notes, and snippets.

@viliml
Created June 15, 2016 11:17
Show Gist options
  • Save viliml/81e33ead3da96e19c6a662ddd12e406e to your computer and use it in GitHub Desktop.
Save viliml/81e33ead3da96e19c6a662ddd12e406e to your computer and use it in GitHub Desktop.
CEOI 2011 day 2, hotel
#include <bits/stdc++.h>
using namespace std;
multiset<pair<int, int>> rooms;
multiset<pair<int, int>, greater<pair<int, int>>> offers;
vector<int> profits;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, o;
int p, q;
long long sol = 0;
cin>>n>>m>>o;
while (n--)
{
cin>>p>>q;
rooms.emplace(q, p);
}
while (m--)
{
cin>>p>>q;
offers.emplace(p, q);
}
for (auto& offer: offers)
{
auto it = rooms.lower_bound({offer.second, 0});
if (it == rooms.end())
continue;
profits.push_back(offer.first - it->second);
rooms.erase(it);
}
sort(profits.begin(), profits.end(), greater<int>());
for (int i = 0; i < o && profits[i] > 0; ++i)
{
sol += profits[i];
}
cout<<sol<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment