Codeforces Problem 332C - Student's Revenge(未A)

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 2
5 6
5 8
1 3
4 3
4 11
output
3 1 2 
input
5 3 3
10 18
18 17
10 20
20 18
20 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个规则,然后在这p个规则中,主席有k个规则是一定会遵守的


1.每个规则都有a和b两个参数

a参数代表主席遵守该规则后会长出的灰发数

b参数代表主席不遵守该规则后董事会的不满度


2.在学生选出的p个规则中,主席优先考虑的是董事会的不满度


3.要使在使主席灰发数量最多的情况下,不满度也最多


思路:

贪心。。 

以上仅供参考,因为我自己的代码并不能AC。。

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL long long
const int maxn = 1e5+100;
LL n,p,k,a,b,ans[maxn],mib=1e9+10,mib_a;
LL vis1[maxn],vis2[maxn],cnt = 0;
struct node{LL a,b,pos;}rule[maxn];

bool cmp1(node a,node b)//max_a a优先
{
    if(a.a==b.a) return a.b>b.b;
    return a.a>b.a;
}
bool cmp2(node a,node b)//min_b b优先
{
    if(a.b==b.b) return a.a<b.a;
    return a.b<b.b;
}
bool cmp3(node a,node b)//max_b
{
    if(a.b==b.b) return a.a<b.a;
    return a.b>b.b;
}
int main()
{
    scanf("%lld%lld%lld",&n,&p,&k);
    for(int i=1;i<=n;i++){
        scanf("%lld%lld",&a,&b);
        rule[i].a = a ;rule[i].b = b;rule[i].pos = i;
    }
    //最大suma的情况下再找最大sumb
    sort(rule+1,rule+1+n,cmp2);//a b小的排前面
    for(int i=1;i<=p-k;i++)
        vis1[rule[i].pos] = 1;//找出一定不能选的p-k个  选进去一定会被排除
    sort(rule+1,rule+1+n,cmp1);//a b大的排前面
    for(int i=1;i<=n&&cnt<k;i++){//找出能选的中的k个a b较大的(a优先)
        if(vis1[rule[i].pos]) continue;//不能选的则跳过
        ans[cnt++] = rule[i].pos;
        if(mib>rule[i].b){mib = rule[i].b;mib_a = rule[i].a;}
        else if(mib==rule[i].b&&mib_a>rule[i].a) mib_a = rule[i].a;
        vis2[rule[i].pos] = 1;
    }
    sort(rule+1,rule+1+n,cmp3);
    LL cnt1 = cnt;
    for(int i=1;i<=n&&cnt<p;i++){
        if(vis2[rule[i].pos]) continue;//已经被用过则跳过
        if((n-cnt1>p-cnt)&&(rule[i].b>mib||(rule[i].b==mib&&rule[i].a<mib_a)))
        {
            cnt1++;
            continue;
            //剩余的能选的个数比还需要选的个数多时可以选择不选
            //该规则的b若比要答应的最小b来的大 能不选则不选
            //该规则的b若与最小b相等则应判断与对应最小b的a的大小 若a较小 能不选则不选
            
        }
        ans[cnt++] = rule[i].pos;
        cnt1++;
    }
    for(int i=0;i<cnt;i++) {
        if(i) printf(" ");
        printf("%lld",ans[i]);
    }
    return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值