Submission #286277

#TimeUsernameProblemLanguageResultExecution timeMemory
286277shrek12357Schools (IZhO13_school)C++14
15 / 100
720 ms26856 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;

#define ll long long

bool comp(pair<ll, ll> a, pair<ll, ll> b) {
	return (a.second - a.first) > (b.second - b.first);
}

int main() {
	int n, m, s;
	cin >> n >> m >> s;
	multiset<pair<ll, ll>> left;
	vector<pair<ll, ll>> schools;
	for (int i = 0; i < n; i++) {
		ll a, b;
		cin >> a >> b;
		left.insert({ a*-1, b });
		schools.push_back({ a, b });
	}
	sort(schools.begin(), schools.end(), comp);
	ll ans = 0;
	for (int i = 0; i < m; i++) {
		ans += left.begin()->first*-1;
		left.erase(left.begin());
	}
	for (int i = 0; i < s; i++) {
		if (left.find({ schools[i].first*-1, schools[i].second }) != left.end()) {
			ans += schools[i].second;
		}
		else {
			ans += schools[i].second;
			ans -= schools[i].first;
			ans += left.begin()->first*-1;
			left.erase(left.begin());
		}
	}
	cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...