in:
5
0 0 5
3 1 2
5 0 3
7 9 2
9 0 1
out:
4
被 hack 的代码:
#include<bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int N=1e6+5;
int x[N],p[N],c[N],f[N],s[N],t[N];
int q[N];
double k(int p1,int p2){
double xp1=s[p1];
double xp2=s[p2];
double yp1=f[p1]+t[p1];
double yp2=f[p2]+t[p2];
return (yp1-yp2)/((xp1-xp2==0)?1e-18:xp1-xp2);
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
int n;cin>>n;
for(int i=1;i<=n;i++){
cin>>x[i]>>p[i]>>c[i];
}
for(int i=1;i<=n;i++){
s[i]=s[i-1]+p[i];
t[i]=t[i-1]+x[i]*p[i];
}
int h=1,aqua=0;
for(int i=1;i<=n;i++){
while(h<aqua&&k(q[aqua-1],q[aqua])>=k(i-1,q[aqua]))aqua--;
q[++aqua]=i-1;
while(h<aqua&&k(q[h+1],q[h])<=x[i])h++;
int j=q[h];
f[i]=f[j]+c[i]+x[i]*(s[i]-s[j])-(t[i]-t[j]);
}
int mn=f[n];
int i;
for(i=n;i>=1;i--){
if(p[i]!=0)break;
mn=min(f[i],mn);
}
mn=min(f[i],mn);
cout<<mn;
return 0;
}
会输出 6。究其原因是第一个仓库没有成品。