Submission #531915

#TimeUsernameProblemLanguageResultExecution timeMemory
531915Vladth11Schools (IZhO13_school)C++14
100 / 100
256 ms34480 KiB
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "

using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;

const ll NMAX = 300001;
const ll VMAX = 1000001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 447;
const ll nr_of_bits = 21;

pii v[NMAX];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, s, i;
    cin >> n >> m >> s;
    for(i = 1; i <= n; i++){
        cin >> v[i].first >> v[i].second;
    }
    sort(v + 1, v + n + 1);
    priority_queue <int> st;
    ll sol = 0;
    for(i = n; i >= n - m + 1; i--){
        sol += v[i].first;
        st.push(v[i].second - v[i].first);
    }
    multiset <pii> bestm, bests;
    for(i = n - m; i >= 1; i--){
        bestm.insert(v[i]);
        bests.insert({v[i].second, v[i].first});
    }
    for(i = 1; i <= s; i++){
        ll sterge = st.top() + (*bestm.rbegin()).first;
        ll nou = (*bests.rbegin()).first;
        if(sterge > nou){
            sol += sterge;
            pii x = *bestm.rbegin();
            bestm.erase(bestm.find(*bestm.rbegin()));
            bests.erase(bests.find({x.second, x.first}));
            st.pop();
            st.push(x.second - x.first);
        }else{
            sol += nou;
            pii x = *bests.rbegin();
            bests.erase(bests.find(*bests.rbegin()));
            bestm.erase(bestm.find({x.second, x.first}));
        }
    }
    cout << sol;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...