按照ai/bi降序排序,依次选择直到满足b的总和等于B,若a总和不能超过A,则“-1 -1“
(!!!Tips bi可能是0;x.a/x.b>y.a/y.b == x.a*y.b>y.a*x.b)
虽然给的样例长这样,但是题目给了误差范围,实际输出会卡精度
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<fstream>
#include<math.h>
#include<stack>
using namespace std;
typedef long long ll;
const double eps=0.000000001;
int n;
double A,B;
struct F{
double g;
int i;
double a;
double b;
};
F fo[100005];
bool cmp(F x,F y){
return x.a*y.b>y.a*x.b;
}
double ans[100005];
int main(){
freopen("burrito.in","r",stdin);
freopen("burrito.out","w",stdout);
scanf("%d%lf%lf",&n,&A,&B);
for(int i=0;i<n;i++){
scanf("%lf%lf%lf",&fo[i].g,&fo[i].a,&fo[i].b);
fo[i].i=i;
}
sort(fo,fo+n,cmp);
double as=0,bs=0;
as=fo[0].g*fo[0].a;
bs=fo[0].g*fo[0].b;
memset(ans,0,sizeof(ans));
bool f=0;
if(bs>B){
bs=B;
B/=fo[0].b;
as=B*fo[0].a;
ans[fo[0].i]=B;
}
else{
ans[fo[0].i]=fo[0].g;
for(int i=1;i<n;i++){
if(f==0){
double k=fo[i].b*fo[i].g;
if(k+bs<=B){
bs+=k;
as+=fo[i].g*fo[i].a;
ans[fo[i].i]=fo[i].g;
}
else{
k=(B-bs)/fo[i].b;
bs=B;
as+=fo[i].a*k;
ans[fo[i].i]=k;
f=1;
}
}
else{
break;
}
}
}
if(as<A)printf("-1 -1\n");
else{
printf("%.8lf %.8lf\n",as,bs);
for(int i=0;i<n;i++){
printf("%.8lf",ans[i]);
if(i==n-1)printf("\n");
else printf(" ");
}
}
return 0;
}