CF332C Students' Revenge

Luo Valley

CF

analysis

Suppose we elected \ (p \) task, then the chairman will certainly follow it: \ (XB> Yb \) , \ (XA <Ya \) are sorted to sort, then select the first \ (k \ ) a task is completed. So let's sort this way, after the \ (pk \) one is the President will not be selected, it can be marked with tags.

Our aim is to make it \ (k \) task of \ (suma \) maximum, additional \ (pk \) task of \ (sumb \) maximum. Then we will \ (n \) tasks in accordance with \ (xa> ya \) sorting, in order to allow these to be the Chairman of the election, we have to take \ (xb> yb \) as the second sort. So we found a chairman to make the election \ (k \) task after that is sorted before \ (k \) months.

Finally, according to the first sort order, select chosen (\ k) \ a later mission \ (pk \) months, so not only guarantee in accordance with (b \) \ descending order, but also make \ (pk \) task of \ (maxb \) is less than \ (k \) task of \ (minB \) , namely, the Chairman will choose us choose a good \ (k \) tasks.

Code

#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 100005
#define il inline
#define re register
#define tie0 cin.tie(0),cout.tie(0)
#define fastio ios::sync_with_stdio(false)
#define File(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout)
using namespace std;
typedef long long ll;

template <typename T> inline void read(T &x) {
    T f = 1; x = 0; char c;
    for (c = getchar(); !isdigit(c); c = getchar()) if (c == '-') f = -1;
    for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x *= f;
}

struct task {
    int a, b, id, tag;
} t[N];

int n, p, k, cnt, num;
bool vis[N];

bool pre(task x, task y) {
    if (x.b != y.b) return x.b < y.b;
    if (x.a != y.a) return x.a > y.a;
    return x.tag < y.tag;
}

bool stu(task x, task y) {
    return x.a == y.a ? x.b > y.b : x.a > y.a;
}

int main() {
    read(n), read(p), read(k);
    for (int i = 1; i <= n; ++i) read(t[i].a), read(t[i].b), t[i].id = i;
    sort(t + 1, t + 1 + n, pre);
    for (int i = 1; i <= p - k; ++i) t[i].tag = 1;
    sort(t + 1, t + 1 + n, stu);
    for (int i = 1; cnt < k; ++i)
        if (!t[i].tag) {
            cnt++;
            printf("%d ", t[i].id);
            vis[t[i].id] = 1;
            t[i].tag = 2;
        }
    cnt = 0;
    sort(t + 1, t + 1 + n, pre);
    for (int i = n; cnt < p - k; --i) {
        if (num >= k) {
            cnt++;
            printf("%d ", t[i].id);
        }
        if (vis[t[i].id]) num++;
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/hlw1/p/11503125.html