Submission #17569

#TimeUsernameProblemLanguageResultExecution timeMemory
17569gs14004Schools (IZhO13_school)C++14
55 / 100
2000 ms18056 KiB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <bitset>
#include <iostream>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;

int n, m, s;
pi a[300005];

multiset<pi> lev1, lev2;
int main(){
	cin >> n >> m >> s;
	for(int i=0; i<n; i++){
		scanf("%d %d",&a[i].first, &a[i].second);
	}
	sort(a, a+n);
	reverse(a, a+n);
	lint ret = 0, tret = 0;
	for(int i=0; i<m; i++){
		ret += a[i].first;
		lev2.insert(pi(a[i].first, a[i].second));
	}
	for(int i=m; i<n; i++){
		lev1.insert(pi(a[i].first, a[i].second));
	}
	tret = ret;
	for(int i=0; i<s; i++){
		int prof1 = -1e9, prof2 = -1e9, prof3 = -1e9;
		pi pp1, pp2, pp3;
		for(auto &i : lev1){
			if(prof1 < i.second){
				prof1 = i.second;
				pp1 = i;
			}
			if(prof2 < i.first){
				prof2 = i.first;
				pp2 = i;
			}
		}
		for(auto &i : lev2){
			if(prof3 < i.second - i.first){
				prof3 = i.second - i.first;
				pp3 = i;
			}
		}
		if(prof1 > prof2 + prof3){
			ret += prof1;
			lev1.erase(pp1);
		}
		else{
			ret += prof2 + prof3;
			lev2.erase(pp3);
			lev2.insert(pp2);
			lev1.erase(pp2);
		}
		tret = max(tret, ret);
		// case 1. get s from empty set
		// case 2. get s from nonempty + get m from empty
		// case 3. 
	}
	cout<< tret;
}
#Verdict Execution timeMemoryGrader output
Fetching results...