Submission #164413

#TimeUsernameProblemLanguageResultExecution timeMemory
164413tselmegkh학교 설립 (IZhO13_school)C++14
75 / 100
530 ms12504 KiB
#include<bits/stdc++.h>
using namespace std;

const int N = 3e5 + 5;
int sum[N][2];

int main(){
	int n, m, s;
	cin >> n >> m >> s;
	
	vector<pair<int, pair<int, int>>> v1;
	for(int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		v1.push_back({a - b, {a, b}});
	}
	sort(v1.rbegin(), v1.rend());

	int tot = 0;
	multiset<int> ms;
	for(int i = 0; i < n; i++){
		ms.insert(v1[i].second.first);
		tot += v1[i].second.first;
		if(ms.size() > m){
			tot -= *ms.begin();
			ms.erase(ms.begin());
		}
		sum[i + 1][0] = tot;
	}
	tot = 0;
	ms.clear();
	for(int i = n - 1; i >= 0; i--){
		ms.insert(v1[i].second.second);
		tot += v1[i].second.second;
		if(ms.size() > s){
			tot -= *ms.begin();
			ms.erase(ms.begin());
		}
		sum[i + 1][1] = tot;
	}
	int ans = 0;
	for(int i = m; i <= n - s; i++){
		ans = max(ans, sum[i][0] + sum[i + 1][1]);
	}
	cout << ans << '\n';
}

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:24:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(ms.size() > m){
      ~~~~~~~~~~^~~
school.cpp:35:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(ms.size() > s){
      ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...