Submission #1063549

#TimeUsernameProblemLanguageResultExecution timeMemory
1063549VMaksimoski008Schools (IZhO13_school)C++17
100 / 100
195 ms16076 KiB
#include <bits/stdc++.h>
//#define int long long

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;

signed main() {
    int n, a, b;
    cin >> n >> a >> b;

    vector<pii> v(n);
    for(auto &x : v) cin >> x.first >> x.second;
    sort(v.rbegin(), v.rend());

    ll pref=0, suf=0;
    priority_queue<int> pq;
    for(int i=0; i<a; i++) {
        pref += v[i].first;
        pq.push(v[i].second - v[i].first);
    }

    multiset<ll> ms;
    for(int i=a; i<n; i++) ms.insert(v[i].second), suf += v[i].second;

    while(ms.size() > b) {
        suf -= *ms.begin();
        ms.erase(ms.begin());
    }

    ll ans = pref + suf;
    for(int i=a; i<a+b; i++) {
        pref += v[i].first;

        pq.push(v[i].second - v[i].first);
        pref += pq.top(); pq.pop();

        suf -= *ms.lower_bound(v[i].second);
        ms.erase(ms.lower_bound(v[i].second));

        ans = max(ans, pref + suf);
    }

    cout << ans << '\n';
    return 0;
}

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:32:21: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |     while(ms.size() > b) {
      |           ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...