Submission #100281

#TimeUsernameProblemLanguageResultExecution timeMemory
100281choikiwonSchools (IZhO13_school)C++17
100 / 100
185 ms7664 KiB
#include<bits/stdc++.h>
using namespace std;

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

const int MN = 300010;

int N, M, S;
pii P[MN];
priority_queue<int> pq;
ll dp[MN], cost;

int main() {
    scanf("%d %d %d", &N, &M, &S);

    for(int i = 0; i < N; i++) {
        scanf("%d %d", &P[i].first, &P[i].second);
    }

    sort(P, P + N);
    reverse(P, P + N);

    for(int i = 0; i < M; i++) {
        pq.push(P[i].second - P[i].first);
        cost += P[i].first;
    }
    dp[M - 1] = cost;
    for(int i = M; i < M + S; i++) {
        pq.push(P[i].second - P[i].first);
        cost += P[i].first;
        cost += pq.top(); pq.pop();
        dp[i] = cost;
    }

    ll ans = dp[M + S - 1];

    while(!pq.empty()) pq.pop();
    for(int i = M + S; i < N; i++) pq.push(P[i].second);
    cost = 0;
    for(int i = M + S - 2; i >= M - 1; i--) {
        pq.push(P[i + 1].second);
        cost += pq.top(); pq.pop();
        ans = max(ans, dp[i] + cost);
    }
    printf("%lld", ans);
}

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &N, &M, &S);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &P[i].first, &P[i].second);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...