rt,开了 long double,为了防止爆 long long 开了 __int128,比较实数大小开了 eps(1e-15),判了 pn=0 的情况,洛谷上目前所有的 Hack 数据都是对的,但 WA on #13。
#include <bits/stdc++.h>
#define _for(i, a, b) for (int i = (a); i <= (b); i ++ )
#define ll __int128
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const ld eps = 1e-15, inf = 1e18 + 5;
int n, hd = 1, tl = 0, q[N], x[N], p[N], c[N]; ll ans, pre[N], s[N], f[N];
inline int sign(ld x) { return fabs(x) < eps ? 0 : (x > 0 ? 1 : - 1); }
inline ld X(int i) { return 1.0 * pre[i]; }
inline ld Y(int i) { return 1.0 * f[i]; }
inline ld slope(int i, int j) { return sign(X(i) - X(j)) ? 1.0 * (Y(i) - Y(j)) / (X(i) - X(j)) : inf; }
int main() {
ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n, pre[0] = 0;
_for (i, 1, n) cin >> x[i] >> p[i] >> c[i], pre[i] = pre[i - 1] + p[i];
_for (i, 1, n) s[i] = x[n] - x[i], f[0] += s[i] * p[i];
ans = f[0], q[ ++ tl] = 0;
_for (i, 1, n - 1) {
while (hd < tl && sign(slope(q[hd], q[hd + 1]) + s[i]) <= 0) hd ++ ;
f[i] = f[q[hd]] - s[i] * (pre[i] - pre[q[hd]]) + c[i], ans = min(ans, f[i]);
while (hd < tl && sign(slope(q[tl], q[tl - 1]) - slope(q[tl], i)) >= 0) tl -- ;
q[ ++ tl] = i;
}
cout << (long long)ans + (long long)(p[n] ? c[n] : 0) << "\n";
return 0;
}