답안 #949487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
949487 2024-03-19T09:36:51 Z LOLOLO 학교 설립 (IZhO13_school) C++17
70 / 100
106 ms 10688 KB
#include <bits/stdc++.h>
typedef long long ll;

#define           f    first
#define           s    second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)

using namespace std;
const int N = 4e5 + 100;

bool cmp(pair <int, int> A, pair <int, int> B) {
    return A.f - A.s > B.f - B.s;
}

ll pr[N], suff[N];

int solve() {
    int n, m, s;
    cin >> n >> m >> s;

    vector <pair <int, int>> save;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        save.pb({a, b});
    }

    sort(all(save), cmp);
    priority_queue <ll, vector <ll>, greater <ll>> pq;
    ll sum = 0;

    for (int i = 0; i < n; i++) {
        pq.push(save[i].f);
        sum += save[i].f;
        while (sz(pq) > m) {
            sum -= pq.top();
            pq.pop();
        }

        pr[i] = sum;
    }

    while (sz(pq))
        pq.pop();

    sum = 0;
    for (int i = n - 1; i >= 0; i--) {
        pq.push(save[i].s);
        sum += save[i].s;
        while (sz(pq) > s) {
            sum -= pq.top();
            pq.pop();
        }

        suff[i] = sum;
    }

    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if (n - i - 1 >= s && i >= m - 1)
            ans = max(ans, pr[i] + suff[i + 1]);
    }

    return ans;
}

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

    int t = 1;
    //cin >> t;

    while (t--) {
        cout << solve() << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Correct 3 ms 2512 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2480 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 2 ms 2476 KB Output is correct
11 Correct 2 ms 2648 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 13 ms 5340 KB Output is correct
14 Correct 26 ms 5996 KB Output is correct
15 Correct 45 ms 6196 KB Output is correct
16 Incorrect 57 ms 9160 KB Output isn't correct
17 Incorrect 73 ms 8796 KB Output isn't correct
18 Incorrect 81 ms 8900 KB Output isn't correct
19 Incorrect 86 ms 9416 KB Output isn't correct
20 Incorrect 106 ms 10688 KB Output isn't correct