#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX_N = 101000;
const int INF = 100000000;
int n,m;
int v[MAX_N], w[MAX_N];
int ans[MAX_N];
struct P{
double first;
int second;
bool operator < (const P& x) const {
return first > x.first;
}
};
P y[MAX_N];
bool C(double x){
for(int i = 0; i < n; i++){
y[i].first = v[i] - x * w[i];
y[i].second = i;
}
sort(y, y + n);
double sum = 0;
for(int i = 0;i < m; i++){
sum += y[i].first;
ans[i] = y[i].second;
}
return sum >= 0;
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 0;i < n; i++){
scanf("%d%d", &v[i], &w[i]);
}
double ub = INF, lb = 0;
for(int i = 0; i < 30 ; i++){
double mid = (lb + ub) / 2;
if(C(mid)) lb = mid;
ub = mid;
}
for(int i = 0;i < m; i++){
printf("%d%c", ans[i] + 1, (i == (m-1)) ? '\n' : ' ');
}
return 0;
}
poj 3111 K Best
最新推荐文章于 2021-10-27 13:39:51 发布