codeforce 332C Students' Revenge

来源:互联网 发布:泛洪算法 编辑:程序博客网 时间:2024/05/22 04:31
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 followingn 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.

Sample test(s)
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个,某主席要在通过的p个中选择k个接受。

每个任务有两个值ai,bi, ai表示如果该主席接受该命令,她的头发变灰的数量,bi表示如果该主席不接受该命令时,议员不高兴值。

对于通过的p个命令,该主席要使议员的不高兴值和最小,在相同的情况下,要使自己的头发变灰的数量尽可能的少。

让你求出通过哪p个命令,使得该主席的头发变灰的数量最多,在相同的情况下,输出使议员不高兴最大的选择。

题解:贪心

第一步:先按 b: 大->小, a: 小->大排序,标记前p-k个,这p-k个一定不能在第二步选,因为b较小,而先选k个b较大的,故总是选不到他们  
第二步;按 a: 大->小, b: 大->小将第一步未标记的数对排序,选出前k个,那么就保证了选出的a的和最大
第三步:将剩下的n-k个数按 b:大->小, a:小->大排序,使选出的b的和最大,然而直接这么写wa了(注释的那一段代码wa test8),正解是记录
第二步取到最小b值得位置,然后在第一步大排序结果中去剩下的p-k个数对。个人还没发现前面那种方法有什么错误,感觉同一个数组
第一次第三次同样的排序方法排的顺序应该是一样的 

附上AC代码

/*author: tpblueskytime:2015年8月7日12:20:46 */#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <string>#include <vector>#include <set>#include <map>#include <queue>#include <string>#include <sstream>#define inf 0x3f3f3f3f#define eps 1e-8#define sqr(x) ((x)*(x))using namespace std;typedef long long ll;const int maxn = 100005;struct node{int a, b, num, pos;int operator<(const node & n) const{if(b != n.b)return b < n.b;return a > n.a;}}ord[maxn], temp[maxn];int comp(node &n1, node &n2){if(n1.a != n2.a)return n1.a > n2.a;else return n1.b > n2.b;}int n, p, k, ans[maxn];int main(){    while(scanf("%d%d%d",&n,&p,&k) == 3)    {    for(int i = 1;i <= n;++i)    {    scanf("%d%d",&ord[i].a,&ord[i].b);    ord[i].num = i;}sort(ord+1,ord+n+1);for(int i = 1;i <= n;++i){temp[i] = ord[i];ord[i].pos = i;}sort(ord+1+p-k,ord+n+1,comp);int cnt = 1, t = inf;for(int i = 1+p-k;i < p+1;++i){ans[cnt++] = ord[i].num;t = min(t,ord[i].pos);}/*sort(ord+1,ord+n+1);for(int i = 1;i <= p-k;++i)ans[cnt++] = ord[t-i].num;*/for(int i = 1;i <= p-k;++i)ans[cnt++] = temp[t-i].num;for(int i = 1;i <= p;++i)printf(i == p?"%d\n":"%d ",ans[i]);}    return 0;}



0 0