1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include <bits/stdc++.h> #define max(a,b) a>b?a:b using namespace std; inline int gin(){ int s=0,f=1; char c=getchar(); while(c<'0' || c>'9'){ if(c=='-') f=-1; c=getchar(); } while(c>='0'&&c<='9'){ s=(s<<3)+(s<<1)+(c^48); c=getchar(); } return s*f; }
const int N=1e5+5,inf=1e9; int st[N],n; double A[N],B[N],R[N],f[N],s;
struct node{ int id; double x,y; }t[N],tmp[N]; inline bool cmp(node a,node b){ return -(A[a.id]/B[a.id]) > -(A[b.id]/B[b.id]); }
double slope(int x,int y){ if(t[x].x==t[y].x) return inf; return (t[y].y-t[x].y)/(t[y].x-t[x].x); }
void cdq(int l,int r){ if(l==r){ f[l]=max(f[l],f[l-1]); t[l].x=f[l]/(A[l]*R[l]+B[l])*R[l]; t[l].y=f[l]/(A[l]*R[l]+B[l]); return; } int mid=l+r>>1,p=l,q=mid+1; for(int i=l;i<=r;i++){ if(t[i].id<=mid) tmp[p++]=t[i]; else tmp[q++]=t[i]; } for(int i=l;i<=r;i++) t[i]=tmp[i]; cdq(l,mid); q=0,p=1; for(int i=l;i<=mid;i++){ while(q>1 && slope(st[q-1],st[q])<slope(st[q],i)) q--; st[++q]=i; } for(int i=mid+1;i<=r;i++){ while(p<q && slope(st[p],st[p+1])>-A[t[i].id]/B[t[i].id]) p++; f[t[i].id]=max(f[t[i].id],t[st[p]].x*A[t[i].id]+t[st[p]].y*B[t[i].id]); } cdq(mid+1,r); p=l,q=mid+1; for(int i=l;i<=r;i++){ if(q>r || p<=mid && t[p].x<t[q].x) tmp[i]=t[p++]; else tmp[i]=t[q++]; } for(int i=l;i<=r;i++) t[i]=tmp[i]; return; }
signed main(){ n=gin(); scanf("%lf",&s); for(int i=1;i<=n;i++){ scanf("%lf%lf%lf",&A[i],&B[i],&R[i]); double x=s/(A[i]*R[i]+B[i])*R[i]; double y=s/(A[i]*R[i]+B[i]); t[i]=(node){i,x,y}; f[i]=s; } sort(t+1,t+n+1,cmp); cdq(1,n); printf("%.3lf\n",f[n]); return 0; }
|