Submission #235541

# Submission time Handle Problem Language Result Execution time Memory
235541 2020-05-28T13:19:52 Z golazcc83 Schools (IZhO13_school) C++14
25 / 100
136 ms 12784 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;
} c[MAXN];

struct descCompBA{
    bool operator()(const city &s1, const city &s2) {
        return s1.b - s1.a < s2.b - s2.a;
    }
};

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

ll An[MAXN], Bn[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);
    
    ll res = 0;
    priority_queue<city, vector<city>, descCompBA> pq;
    for(int i = 0; i < M; ++i) {
        res += c[i].a;
        pq.push(c[i]);
    }

    for(int i = M; i < M + S; ++i) {
        city tc = pq.top();
        if(c[i].b - c[i].a > tc.b - tc.a)
            res += c[i].b;
        else {
            res += c[i].a + tc.b - tc.a;
            pq.pop();
            pq.push(c[i]);
        }
    }

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

Compilation message

school.cpp: In function 'int main()':
school.cpp:32: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:34: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 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Incorrect 5 ms 384 KB Output isn't correct
6 Incorrect 5 ms 384 KB Output isn't correct
7 Incorrect 6 ms 512 KB Output isn't correct
8 Correct 8 ms 744 KB Output is correct
9 Incorrect 7 ms 640 KB Output isn't correct
10 Incorrect 7 ms 640 KB Output isn't correct
11 Incorrect 6 ms 512 KB Output isn't correct
12 Incorrect 7 ms 640 KB Output isn't correct
13 Incorrect 20 ms 2556 KB Output isn't correct
14 Incorrect 38 ms 4088 KB Output isn't correct
15 Incorrect 67 ms 6264 KB Output isn't correct
16 Correct 86 ms 7684 KB Output is correct
17 Incorrect 100 ms 10348 KB Output isn't correct
18 Incorrect 110 ms 11092 KB Output isn't correct
19 Incorrect 117 ms 11628 KB Output isn't correct
20 Incorrect 136 ms 12784 KB Output isn't correct