Submission #342453

# Submission time Handle Problem Language Result Execution time Memory
342453 2021-01-02T07:01:48 Z IZhO_2021_I_want_Silver Schools (IZhO13_school) C++14
95 / 100
309 ms 19448 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>-

using namespace std;
//using namespace __gnu_pbds;

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

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define show(a) cerr << #a <<" -> "<< a <<" "
#define nl cerr <<"\n"
#define int ll

const int N = 3e5 + 5;
const int oo = 1e9 + 5;

int n, m, s, a[N], b[N], ans, pref[N], suf[N];
vector <pii> vec;
multiset <int> st;

void solve() {
    cin >> n >> m >> s;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i] >> b[i];
        vec.pb({a[i]-b[i], i});
    }
    sort(all(vec));

    int sum = 0;
    if (s > 0) {
        for (int i = 0; i < s; ++i) {
            int ind = vec[i].S;
            st.insert(b[ind]);
            sum += b[ind];
        }
        pref[s-1] = sum;
        for (int i = s; i < sz(vec); ++i) {
            int ind = vec[i].S, mn = *st.begin();
            if (b[ind] > mn) {
                st.erase(st.find(mn));
                st.insert(b[ind]);
                sum -= mn;
                sum += b[ind];
            }
            pref[i] = sum;
        }
        st.clear();
    }

    if (m > 0) {
        sum = 0;
        for (int i = sz(vec)-1; i >= sz(vec)-m; --i) {
            int ind = vec[i].S;
            st.insert(a[ind]);
            sum += a[ind];
        }
        suf[sz(vec)-m] = sum;
        for (int i = sz(vec)-m-1; i >= 0; --i) {
            int ind = vec[i].S, mn = *st.begin();
            if (a[ind] > mn) {
                st.erase(st.find(mn));
                st.insert(a[ind]);
                sum -= mn;
                sum += a[ind];
            }
            suf[i] = sum;
        }
        st.clear();
    }

    for (int i = max(s - 1, 0ll); i < sz(vec) - m; ++i) {
        ans = max(ans, pref[i]+suf[i+1]);
    }
    cout << ans;
}

 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tests = 1;
	//cin >> tests;
	while (tests --) {
		solve();
	}
	return 0;
}
/*
    Just Chalish!
*/

Compilation message

school.cpp:101:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  101 |  main () {
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 4 ms 620 KB Output is correct
8 Correct 4 ms 748 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 5 ms 748 KB Output is correct
11 Correct 5 ms 748 KB Output is correct
12 Correct 3 ms 748 KB Output is correct
13 Correct 25 ms 3436 KB Output is correct
14 Correct 40 ms 5096 KB Output is correct
15 Correct 56 ms 8568 KB Output is correct
16 Correct 209 ms 15332 KB Output is correct
17 Correct 228 ms 15076 KB Output is correct
18 Correct 211 ms 15588 KB Output is correct
19 Correct 278 ms 16880 KB Output is correct
20 Correct 309 ms 19448 KB Output is correct