답안 #89017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89017 2018-12-10T08:19:12 Z temoyanteladze 학교 설립 (IZhO13_school) C++14
100 / 100
603 ms 35324 KB
//outsider
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
using namespace std;

int main() {
ll n,l,r;
ll ans=0;
vector<pair<ll,ll> >a;

    cin>>n>>l>>r;
    a.resize(n+1);
	for(ll i=1;i<=n;i++)
		cin>>a[i].x>>a[i].y;

	sort(a.begin()+1,a.end());
	reverse(a.begin()+1,a.end());

	multiset<ll>q;
    multiset <pair<ll,ll> > os1,os2;

	for(ll i=1;i<=l;i++)
	{
		ans+=a[i].x;
		q.insert(-a[i].y+a[i].x);
	}

	for(ll i=l+1;i<=n;i++)
	{
		os1.insert(a[i]);
		os2.insert({a[i].y,a[i].x});
	}

	for (ll i=r;i>0;i--){
		pair<ll,ll>fat,sad;
		fat=*os1.rbegin();
	    sad=*os2.rbegin();
	    ll f1=-*q.begin();

		if(f1+fat.x>sad.x)
		{
			ans+=f1+fat.x;
			q.erase(q.begin());
			ll p=fat.y-fat.x;
			q.insert(-p);
			os1.erase(os1.find(fat));
			os2.erase(os2.find({fat.y, fat.x}));

		}
		 else{
			ans +=sad.x;
			os2.erase(os2.find(sad));
			os1.erase(os1.find({sad.y, sad.x}));
		 }
	}
cout<< ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 8 ms 1108 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 7 ms 1108 KB Output is correct
10 Correct 7 ms 1108 KB Output is correct
11 Correct 10 ms 1220 KB Output is correct
12 Correct 10 ms 1256 KB Output is correct
13 Correct 43 ms 3176 KB Output is correct
14 Correct 160 ms 10980 KB Output is correct
15 Correct 330 ms 22944 KB Output is correct
16 Correct 516 ms 24180 KB Output is correct
17 Correct 464 ms 24844 KB Output is correct
18 Correct 505 ms 27260 KB Output is correct
19 Correct 519 ms 29948 KB Output is correct
20 Correct 603 ms 35324 KB Output is correct