Submission #235593

# Submission time Handle Problem Language Result Execution time Memory
235593 2020-05-28T18:01:03 Z golazcc83 Schools (IZhO13_school) C++14
25 / 100
176 ms 20556 KB
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

#define MINF -1000000000000000000

using namespace std;
typedef long long ll;

const int MAXN = 300001;
int N, M, S;

struct city {
    ll a, b, idx;
} c[MAXN];

bool descCompA(const city &s1, const city &s2) {
    if(s1.a != s2.a)
        return s1.a > s2.a;
    return s1.b > s2.b;
}

bool descCompB(const city &s1, const city &s2) {
    return s1.b > s2.b;
}

struct ascCompBA{
    bool operator()(const city &s1, const city &s2) {
        if(s1.b - s1.a != s2.b - s2.a)
            return s1.b - s1.a < s2.b - s2.a;
        return s1.b > s2.b;
    }
};

ll An[MAXN], Bn[MAXN];
int con[MAXN];

int main() {
    scanf("%d %d %d", &N, &M, &S);
    for(int i = 0; i < N; ++i) {
        scanf("%lld %lld", &An[i], &Bn[i]);
        c[i].a = An[i];
        c[i].b = Bn[i];
    }

    sort(c, c + N, descCompA);
    for(int i = 0; i < N; ++i)
        c[i].idx = i;
    
    ll res = 0;
    priority_queue<city, vector<city>, ascCompBA> pqsm;
    fill(con, con + M, 1);
    for(int i = 0; i < M; ++i) {
        res += c[i].a;
        pqsm.push(c[i]);
    }

    for(int i = M; i < M + S; ++i) {
        city tc = pqsm.top();
        if(c[i].b - c[i].a >= tc.b - tc.a) {
            res += c[i].b;
            con[i] = 2;
        }
        else {
            res += c[i].a + tc.b - tc.a;
            pqsm.pop();
            pqsm.push(c[i]);
            con[i] = 1;
            con[tc.idx] = 2;
        }
    }
    
    priority_queue<ll, vector<ll>, greater<ll>> pqm;
    for(int i = 0; i < M + S; ++i)
        if(con[i] == 2)
            pqm.push(c[i].b);

    sort(c + M + S, c + N, descCompB);
    for(int i = M + S; i < N; ++i) {
        if(c[i].b > pqm.top()) {
            res += c[i].b - pqm.top();
            pqm.pop();
            pqm.push(c[i].b);
        }
        else
            break;
    }

    printf("%lld\n", res);
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:40: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:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", &An[i], &Bn[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Incorrect 4 ms 384 KB Output isn't correct
6 Incorrect 4 ms 384 KB Output isn't correct
7 Incorrect 6 ms 640 KB Output isn't correct
8 Correct 6 ms 896 KB Output is correct
9 Incorrect 8 ms 768 KB Output isn't correct
10 Incorrect 9 ms 768 KB Output isn't correct
11 Incorrect 7 ms 640 KB Output isn't correct
12 Incorrect 7 ms 640 KB Output isn't correct
13 Incorrect 21 ms 3196 KB Output isn't correct
14 Incorrect 44 ms 4988 KB Output isn't correct
15 Incorrect 87 ms 8440 KB Output isn't correct
16 Correct 90 ms 13164 KB Output is correct
17 Incorrect 119 ms 16100 KB Output isn't correct
18 Incorrect 123 ms 17128 KB Output isn't correct
19 Incorrect 143 ms 18296 KB Output isn't correct
20 Incorrect 176 ms 20556 KB Output isn't correct