大米饼写的太棒辣qwqqwq
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
int n, l, r, que[1000005];
ll x[1000005], p[1000005], c[1000005], dp[1000005], q[1000005];
struct Node{
ll x, y;
}nd[1000005];
double getK(Node u, Node v){
return (double)(u.y-v.y)/(u.x-v.x);
}
int main(){
cin>>n;
for(int i=1; i<=n; i++){
scanf("%lld %lld %lld", &x[i], &p[i], &c[i]);
q[i] = q[i-1] - x[i] * p[i];
p[i] = p[i-1] + p[i];
}
for(int i=1; i<=n; i++){
dp[i] = x[i] * p[i-1] + q[i-1] + c[i];
while(l<r && getK(nd[que[l]],nd[que[l+1]])<x[i]) l++;
int j=que[l];
dp[i] = min(dp[i], dp[j]+x[i]*(p[i-1]-p[j])+q[i-1]-q[j]+c[i]);
nd[i] = (Node){p[i], dp[i]-q[i]};
while(l<r && getK(nd[que[r]],nd[que[r-1]])>=getK(nd[que[r]], nd[i]))
r--;
que[++r] = i;
}
cout<<dp[n]<<endl;
return 0;
}