Submission #84398

#TimeUsernameProblemLanguageResultExecution timeMemory
84398ekremSchools (IZhO13_school)C++98
100 / 100
433 ms39740 KiB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

typedef pair < int , int > ii;

int n, x, y;
long long ans;
ii a[N];
priority_queue < int > q;
multiset < ii > s, t;

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d %d",&n ,&x ,&y);
	for(int i = 1; i <= n; i++)
		scanf("%d %d",&a[i].st ,&a[i].nd);
	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);
	for(int i = 1; i <= x; i++){
		ans += a[i].st;
		q.push(a[i].nd - a[i].st);
	}
	// cout << ans << endl;
	for(int i = x + 1; i <= n; i++){
		s.insert(a[i]);
		t.insert(mp(a[i].nd, a[i].st));
	}
	while(y--){
		int frk = q.top();
		ii son = *s.rbegin();
		ii alma = *t.rbegin();
		if(frk + son.st > alma.st){
			ans += frk + son.st;
			q.pop();
			s.erase(s.find(son));
			t.erase(t.find(mp(son.nd, son.st)));
			q.push(son.nd - son.st);
		} else{
			ans += alma.st;
			t.erase(t.find(alma));
			s.erase(s.find(mp(alma.nd, alma.st)));
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n ,&x ,&y);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
school.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&a[i].st ,&a[i].nd);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...