Codeforces Round #193 (Div. 2)

来源:互联网 发布:淘宝幸运抽奖 编辑:程序博客网 时间:2024/06/05 00:25

C. Students' Revenge
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A student's life is fraught with complications. Some Berland University students know this only too well. Having studied for two years, they contracted strong antipathy towards the chairperson of some department. Indeed, the person in question wasn't the kindest of ladies to begin with: prone to reforming groups, banning automatic passes and other mean deeds. At last the students decided that she just can't get away with all this anymore...

The students pulled some strings on the higher levels and learned that the next University directors' meeting is going to discuss n orders about the chairperson and accept exactly p of them. There are two values assigned to each order: ai is the number of the chairperson's hairs that turn grey if she obeys the order and bi — the displeasement of the directors if the order isn't obeyed. The students may make the directors pass any p orders chosen by them. The students know that the chairperson will obey exactly k out of these p orders. She will pick the orders to obey in the way that minimizes first, the directors' displeasement and second, the number of hairs on her head that turn grey.

The students want to choose p orders in the way that maximizes the number of hairs on the chairperson's head that turn grey. If there are multiple ways to accept the orders, then the students are keen on maximizing the directors' displeasement with the chairperson's actions. Help them.

Input

The first line contains three integers n (1 ≤ n ≤ 105), p (1 ≤ p ≤ n), k (1 ≤ k ≤ p) — the number of orders the directors are going to discuss, the number of orders to pass and the number of orders to be obeyed by the chairperson, correspondingly. Each of the following n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 109), describing the corresponding order.

Output

Print in an arbitrary order p distinct integers — the numbers of the orders to accept so that the students could carry out the revenge. The orders are indexed from 1 to n in the order they occur in the input. If there are multiple solutions, you can print any of them.

Examples
input
5 3 25 65 81 34 34 11
output
3 1 2 
input
5 3 310 1818 1710 2020 1820 18
output
2 4 5 
Note

In the first sample one of optimal solutions is to pass orders 1, 2, 3. In this case the chairperson obeys orders number 1 and 2. She gets 10 new grey hairs in the head and the directors' displeasement will equal 3. Note that the same result can be achieved with order 4 instead of order 3.

In the second sample, the chairperson can obey all the orders, so the best strategy for the students is to pick the orders with the maximum sum of ai values. The chairperson gets 58 new gray hairs and the directors' displeasement will equal 0.



题意:

在n个规则中选择p个,每个规律不遵守的话,议员会有一定的愤怒值b,遵守的话,主席会有一定的白头发a。然后主席会在p个中选k个去遵守,主席的选择一定是要让议员的愤怒值最小的,其次才是自己的白头发。

问你这p个规则怎么选。


POINT:

先给n个规则从b小,在a大的顺序来排,那么前p-k个肯定是b很小,每次选这个规则,都会让主席去不遵守--来让愤怒值最小。

所以这几个规则是主席不考虑遵守的。

在这个基础上,在去排[p-k+1,n]个规则,从a大,b大来排。前k个就是最优的遵守规则。

然后在根据题意找出p-k个就好了。

时刻记住:我们是强迫主席去选愤怒小的,然后留下的却是头发最多的。

#include <iostream>#include <stdio.h>#include <algorithm>using namespace std;const int maxn = 1e5+123;struct node{    int a,b;    int f;    int ff;}a[maxn];bool cmd1(node a,node b){    if(a.b!=b.b) return a.b<b.b;    return a.a>b.a;}bool cmd2(node a,node b){    if(a.a!=b.a) return a.a>b.a;    return a.b>b.b;}struct n1{    int b,f,a;}b[maxn];bool cmd3(n1 a,n1 b){    if(a.b!=b.b)        return a.b>b.b;    return a.a>b.a;}int main(){    int n,k,p;    scanf("%d %d %d",&n,&p,&k);    for(int i=1;i<=n;i++){        scanf("%d %d",&a[i].a,&a[i].b);        a[i].f=i;        a[i].ff=0;    }    sort(a+1,a+1+n,cmd1);    sort(a+p-k+1,a+1+n,cmd2);    int Minb=1e9+2;    int Mina;    int ans[maxn];    int cnt=0;    int num=0;    for(int i=p-k+1;i<=p;i++){        ans[++cnt]=a[i].f;        a[i].ff=1;        if(Minb>a[i].b){            Minb=a[i].b;            Mina=a[i].a;        }    }    for(int i=1;i<=n;i++){        if(a[i].ff!=1){            b[++num].b=a[i].b;            b[num].f=a[i].f;            b[num].a=a[i].a;        }    }    sort(b+1,b+1+num,cmd3);    for(int i=1;i<=num;i++){        if(cnt==p){            break;        }        if(Minb==b[i].b&&b[i].a<Mina) continue;        if(Minb>=b[i].b){            ans[++cnt]=b[i].f;        }    }    for(int i=1;i<=cnt;i++){        if(i-1) printf(" ");        printf("%d",ans[i]);    }}