Submission #638110

# Submission time Handle Problem Language Result Execution time Memory
638110 2022-09-04T15:51:44 Z tvladm2009 Schools (IZhO13_school) C++14
75 / 100
222 ms 15404 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int MAX_N = 3 * 1e5;

int a[MAX_N + 1], b[MAX_N + 1], pref[MAX_N + 1], suf[MAX_N + 1];
pair<int, int> c[MAX_N + 1];
multiset<int> DS;

int n, m, s;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m >> s;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }

    for (int i = 1; i <= n; i++) {
        c[i] = make_pair(b[i] - a[i], i);
    }
    sort(c + 1, c + n + 1);
    int sum = 0;
    for (int i = 1; i <= m; i++) {
        DS.insert(a[c[i].second]);
        sum += a[c[i].second];
    }
    pref[m] = sum;
    for (int i = m + 1; i <= n; i++) {
        DS.insert(a[c[i].second]);
        sum += a[c[i].second];
        sum -= *DS.begin();
        DS.erase(DS.begin());
        pref[i] = sum;
    }
    DS.clear();
    sum = 0;
    for (int i = n - s + 1; i <= n; i++) {
        DS.insert(b[c[i].second]);
        sum += b[c[i].second];
    }
    suf[n - s + 1] = sum;
    for (int i = n - s; i >= 1; i--) {
        DS.insert(b[c[i].second]);
        sum += b[c[i].second];
        sum -= *DS.begin();
        DS.erase(DS.begin());
        suf[i] = sum;
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = max(ans, (ll)pref[i] + suf[i + 1]);
    }
    cout << ans;

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 19 ms 2876 KB Output is correct
14 Correct 36 ms 3932 KB Output is correct
15 Correct 61 ms 6024 KB Output is correct
16 Incorrect 123 ms 13132 KB Output isn't correct
17 Incorrect 152 ms 12188 KB Output isn't correct
18 Incorrect 177 ms 12404 KB Output isn't correct
19 Incorrect 162 ms 13464 KB Output isn't correct
20 Incorrect 222 ms 15404 KB Output isn't correct