답안 #246236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246236 2020-07-08T12:20:50 Z aloo123 학교 설립 (IZhO13_school) C++14
100 / 100
233 ms 21708 KB
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
 
 
const ll INF = 1e12;
const ll N =(1e7+5); // TODO : change value as per problem
const ll MOD = 1e9+7;
ll a[N];
ll b[N];
ll pre[N];
ll suf[N];
pll v[N];
bool cmp(pll x,pll y){
	return ((x.f - x.s) > (y.f-y.s));
}

void solve(){
 	ll n,m,S;
 	cin >> n >> m >> S;
 	for(int i= 1;i<=n;i++){
 		cin >> a[i] >> b[i];
 		v[i].f = a[i];
 		v[i].s = b[i];
 	}
 	sort(v+1,v+n+1,cmp);
 	multiset<ll,greater<ll>> se;
 	ll sum = 0;
 	for(int i = 1;i<=m;i++){
 		se.in(v[i].f);
 		sum += v[i].f;
 	}
 	pre[m] = sum;
 	for(int i= m+1;i<=n;i++){
 		ll add = v[i].f;
 		if(add > *(se.rbegin())){
 			sum -= *(se.rbegin());
 			sum += add;
 			se.erase(se.find(*se.rbegin()));
 			se.in(add);
 		}
 		pre[i] = sum;
 	}
 	se.clear();
 	sum = 0;
 	ll dumb = -1;
 	for(int i = n,j =1;j<=S;j++,i--){
 		sum += v[i].s;
 		se.in(v[i].s);
 		if(j == S){
 			suf[i] = sum;
 			dumb = i;
 		}
 	}
 	for(int i = dumb-1;i>=1;i--){
 		ll add = v[i].s;
 		if(add > *(se.rbegin())){
 			sum -= *(se.rbegin());
 			sum += add;
 			se.erase(se.find(*se.rbegin()));
 			se.in(add);
 		}
 		suf[i] = sum;
 	}
 	ll ans= 0;
 	for(int i =m;i<=n;i++){
 		if((n-i) >= S){
 			ans = max(ans,pre[i] + suf[i+1]);
 		}
 	}
 	cout << ans << endl;



}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    

 
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 9 ms 768 KB Output is correct
9 Correct 7 ms 768 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 8 ms 768 KB Output is correct
13 Correct 26 ms 3712 KB Output is correct
14 Correct 43 ms 5624 KB Output is correct
15 Correct 60 ms 9848 KB Output is correct
16 Correct 150 ms 16888 KB Output is correct
17 Correct 181 ms 16812 KB Output is correct
18 Correct 174 ms 17528 KB Output is correct
19 Correct 195 ms 18808 KB Output is correct
20 Correct 233 ms 21708 KB Output is correct