제출 #894472

#제출 시각아이디문제언어결과실행 시간메모리
894472heeheeheehaaw학교 설립 (IZhO13_school)C++17
25 / 100
285 ms17744 KiB
#include <bits/stdc++.h>
#define int long long

using namespace std;

struct yes
{
    int p, v;
};

yes v1[300005];
yes v2[300005];
bool vis1[300005];
bool vis2[300005];
bool luat[300005];

bool cmp(yes a, yes b)
{
    return a.v > b.v;
}

bool cmp2(int a, int b)
{
    int dif1 = (v1[a].v - v2[a].v), dif2 = (v1[b].v - v2[b].v);
    if(dif1 == dif2)
        return v1[a].v > v2[a].v;
    return dif1 < dif2;
}

bool cmp3(yes a, yes b)
{
    return a.v < b.v;
}

signed main()
{
    int n, m, s;
    cin>>n>>m>>s;
    vector<int> p;
    int rez = 0;
    for(int i = 1; i <= n; i++)
    {
        cin>>v1[i].v>>v2[i].v;
        v1[i].p = v2[i].p = i;
        p.push_back(i);
        vis1[i] = true;
        rez += v1[i].v;
    }

    sort(p.begin(), p.end(), cmp2);
    int cm = n, cs = 0, poz = -1;
    while(cm > m && cs < s)
    {
        poz++;
        cm--, cs++;
        vis1[p[poz]] = false;
        vis2[p[poz]] = true;
        rez -= v1[p[poz]].v;
        rez += v2[p[poz]].v;
    }

    if(cm > m)
    {
        sort(v1 + 1, v1 + n + 1, cmp3);
        poz = 0;
        while(cm > m)
        {
            poz++;
            if(!vis2[v1[poz].p])
                cm--, rez -= v1[poz].v;
        }
    }

    if(cs < s)
    {
        while(1);
    }

    cout<<rez;



    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...