POJ 3111 K Best 【二分:最大化平均值】

来源:互联网 发布:网络销售培训课程 编辑:程序博客网 时间:2024/05/29 04:36

K Best
Time Limit: 8000MS Memory Limit: 65536KTotal Submissions: 10371 Accepted: 2672Case Time Limit: 2000MS Special Judge

Description

Demy has n jewels. Each of her jewels has some value vi and weight wi.

Since her husband John got broke after recent financial crises, Demy has decided to sell some jewels. She has decided that she would keep k best jewels for herself. She decided to keep such jewels that their specific value is as large as possible. That is, denote the specific value of some set of jewels S = {i1i2, …, ik} as

.

Demy would like to select such k jewels that their specific value is maximal possible. Help her to do so.

Input

The first line of the input file contains n — the number of jewels Demy got, and k — the number of jewels she would like to keep (1 ≤ k ≤ n ≤ 100 000).

The following n lines contain two integer numbers each — vi and wi (0 ≤ vi ≤ 106, 1 ≤ wi ≤ 106, both the sum of all vi and the sum of all wi do not exceed 107).

Output

Output k numbers — the numbers of jewels Demy must keep. If there are several solutions, output any one.

Sample Input

3 21 11 21 3

Sample Output

1 2

Source

Northeastern Europe 2005, Northern Subregion


#include<iostream>  #include<cstdio>  #include<cstring>  #include<string>  #include<cmath>  #include<queue>  #include<stack>  #include<vector>  #include<map>  #include<algorithm>  using namespace std;  #define ll long long  #define ms(a,b)  memset(a,b,sizeof(a))  const int M=1e5+10;  const int inf=0x3f3f3f3f;  const int mod=1e9+7; int i,j,k,n,m; int a[M]; int b[M];double y[M];struct node{int num;int v;int w;double y;bool operator < (const node&x) const    {        return y>x.y;    }}p[M];bool cmp(node a,node b){ return a.y>b.y;}int kk[M];bool check(double mid){for(int i=1;i<=n;i++)p[i].y=p[i].v-p[i].w*mid;sort(p+1,p+n+1);double sum=0;for(int i=1;i<=k;i++){       sum+=p[i].y;   kk[i]=p[i].num;}return sum>=0;}int main(){while(~scanf("%d%d",&n,&k)){if(n==0&&k==0)break;for(int i=1;i<=n;i++){scanf("%d %d",&p[i].v,&p[i].w);    p[i].num=i;     }        double lb=0,ub=1000000000;    for(int i=0;i<100;i++){ double mid=(lb+ub)/2;         if(check(mid))lb=mid; else ub=mid;     }     for(int i=1;i<=k;i++)if(i>1)printf(" %d",kk[i]);else printf("%d",kk[i]); printf("\n");   }   return 0;}