提交时间:2021-12-11 21:37:35

运行 ID: 34519

#include<cstdio> #include<cstring> #include<algorithm> #include<ctype.h> #define N 1000010 #define ll long long using namespace std; ll x[N],p[N],c[N],dp[N],n; inline long long Read() { long long ret=0,f=1; char ch=getchar(); while(!isdigit(ch)) { if(ch=='-')f=-f; ch=getchar(); } while(isdigit(ch)) { ret=(ret<<3)+(ret<<1)+ch-'0'; ch=getchar(); } return ret*f; } int main() { n=Read(); for(int i=1; i<=n; i++) x[i]=Read(),p[i]=Read(),c[i]=Read(); memset(dp,0x3f,sizeof(dp)); dp[0]=0; for(int i=1; i<=n; i++) for(int j=0; j<i; j++) { ll t=0; for(int k=j+1; k<i; k++) t+=(x[i]-x[k])*p[k]; dp[i]=min(dp[i],dp[j]+t+c[i]); } printf("%lld",dp[n]); return 0; }