Submission #235536

#TimeUsernameProblemLanguageResultExecution timeMemory
235536golazcc83학교 설립 (IZhO13_school)C++14
5 / 100
175 ms22904 KiB
#include <iostream>
#include <algorithm>
#define MINF -1000000000000000000

using namespace std;
typedef long long ll;

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

struct student {
    ll a, b; int idx;
} A[MAXN], B[MAXN];

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

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

ll An[MAXN], Bn[MAXN];
bool v[MAXN];

int main() {
    scanf("%d %d %d", &N, &M, &S);
    for(int i = 0; i < N; ++i) {
        scanf("%lld %lld", &An[i], &Bn[i]);
        A[i].a = B[i].a = An[i];
        A[i].b = B[i].b = Bn[i];
        A[i].idx = B[i].idx = i;
    }
    sort(A, A + N, compA);
    sort(B, B + N, compB);
    A[N].a = A[N].b = B[N].a = B[N].b = MINF;

    fill(v, v + N + 1, false);

    ll res = 0;
    int ia = 0, ib = 0;
    int ta = 0, tb = 0;

    while(ta != M || tb != S) {
        while(ta != M) {
            if(!v[A[ia].idx]) {
                res += A[ia].a;
                v[A[ia].idx] = true;
                ++ia; ++ta;
                continue;
            }
            ll nxtA = Bn[A[ia].idx] + A[ia + 1].a;
            ll nxtB = B[ib].b + A[ia].a;
            if(nxtA >= nxtB) {
                ++ia;
                continue;
            }
            res += A[ia].a - Bn[A[ia].idx];
            --tb; ++ta;
            ++ia;
        }
        while(tb != S) {
            if(!v[B[ib].idx]) {
                res += B[ib].b;
                v[B[ib].idx] = true;
                ++ib; ++tb;
                continue;
            }
            ll nxtA = An[B[ib].idx] + B[ib + 1].b;
            ll nxtB = A[ia].a + B[ib].b;
            if(nxtA >= nxtB) {
                ++ib;
                continue;
            }
            res += B[ib].b - An[B[ib].idx];
            --ta; ++tb;
            ++ib;
        }
    }

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

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:29: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:31: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 timeMemoryGrader output
Fetching results...