Submission #100281

# Submission time Handle Problem Language Result Execution time Memory
100281 2019-03-10T08:37:12 Z choikiwon Schools (IZhO13_school) C++17
100 / 100
185 ms 7664 KB
#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

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 time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 4 ms 484 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 4 ms 512 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 16 ms 1280 KB Output is correct
14 Correct 34 ms 2296 KB Output is correct
15 Correct 59 ms 4592 KB Output is correct
16 Correct 81 ms 5184 KB Output is correct
17 Correct 110 ms 5972 KB Output is correct
18 Correct 110 ms 6172 KB Output is correct
19 Correct 127 ms 6620 KB Output is correct
20 Correct 185 ms 7664 KB Output is correct