Submission #73814

# Submission time Handle Problem Language Result Execution time Memory
73814 2018-08-29T05:06:07 Z 김세빈(#2276) Schools (IZhO13_school) C++11
100 / 100
456 ms 15636 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;

pll D[303030];
priority_queue <ll> P;
multiset <ll> S;
ll n, x, y;
ll ans, sum1, sum2, sum3;

int main()
{
	ll i;
	
	scanf("%lld%lld%lld", &n, &x, &y);
	
	for(i=1; i<=n; i++){
		scanf("%lld%lld", &D[i].first, &D[i].second);
	}
	
	sort(D + 1, D + n + 1);
	reverse(D + 1, D + n + 1);
	
	for(i=1; i<=x; i++){
		P.push(D[i].second - D[i].first);
		sum1 += D[i].first;
	}
	
	for(i=n; i>x; i--){
		S.insert(D[i].second);
		sum2 += D[i].second;
	}
	for(; S.size() > y; ){
		sum2 -= *S.begin();
		S.erase(S.begin());
	}
	
	ans = sum1 + sum2;
	
	for(i=1; i<=y; i++){
		P.push(D[x + i].second - D[x + i].first);
		sum1 += D[x + i].first;
		sum3 += P.top(); P.pop();
		
		auto it = S.lower_bound(D[x + i].second);
		if(it == S.end() || *it != D[x + i].second){
			sum2 -= *S.begin();
			S.erase(S.begin());
		}
		else{
			sum2 -= D[x + i].second;
			S.erase(it);
		}
		
		ans = max(ans, sum1 + sum2 + sum3);
	}
	
	printf("%lld\n", ans);
	
	return 0;
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:36:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(; S.size() > y; ){
        ~~~~~~~~~^~~
school.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld", &n, &x, &y);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &D[i].first, &D[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 480 KB Output is correct
5 Correct 3 ms 480 KB Output is correct
6 Correct 3 ms 508 KB Output is correct
7 Correct 6 ms 692 KB Output is correct
8 Correct 4 ms 760 KB Output is correct
9 Correct 5 ms 760 KB Output is correct
10 Correct 6 ms 760 KB Output is correct
11 Correct 6 ms 872 KB Output is correct
12 Correct 7 ms 872 KB Output is correct
13 Correct 19 ms 1512 KB Output is correct
14 Correct 98 ms 5096 KB Output is correct
15 Correct 257 ms 10532 KB Output is correct
16 Correct 456 ms 11052 KB Output is correct
17 Correct 248 ms 11052 KB Output is correct
18 Correct 238 ms 12000 KB Output is correct
19 Correct 259 ms 13296 KB Output is correct
20 Correct 316 ms 15636 KB Output is correct