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
| #include <cstdio> #include <algorithm> using namespace std; const int N = 1e5 + 10; const double inf = 1e9, eps = 1e-9; int n, p[N], q[N]; double A[N], B[N], R[N], f[N], X[N], Y[N], K[N]; double slp (int i, int j) { if (X[i] == X[j]) return inf; return (Y[i] - Y[j]) / (X[i] - X[j]); } void cdq (int l, int r) { if (l == r) { f[l] = max(f[l], f[l - 1]); Y[l] = f[l] / (A[l] * R[l] + B[l]); X[l] = Y[l] * R[l]; return; } int mid = l + r >> 1; cdq(l, mid); for (int i = l; i <= r; ++i) p[i] = i; sort(p + l, p + mid + 1, [&](int i, int j) { return X[i] < X[j]; }); sort(p + mid + 1, p + r + 1, [&](int i, int j) { return K[i] > K[j]; }); int hd = 1, tl = 0; for (int i = l; i <= mid; ++i) { while (hd < tl && slp(q[tl], p[i]) > slp(q[tl - 1], q[tl])) --tl; q[++tl] = p[i]; } for (int i = mid + 1; i <= r; ++i) { while (hd < tl && slp(q[hd], q[hd + 1]) > K[p[i]]) ++hd; f[p[i]] = max(f[p[i]], X[q[hd]] * A[p[i]] + Y[q[hd]] * B[p[i]]); } cdq(mid + 1, r); } int main () { scanf("%d%lf", &n, &f[0]); for (int i = 1; i <= n; ++i) { scanf("%lf%lf%lf", &A[i], &B[i], &R[i]); K[i] = -A[i] / B[i]; } cdq(1, n); printf("%.3lf", f[n]); return 0; }
|