# 7.10省队集训梦工厂

g[i]=g[i-1]+max(sum[j]*f[i-1]-sum[j-1]*f[i])

sum[j]*f[i-1]=f[i]*sum[j-1]+g[i]-g[i-1]

sum[j]=f[i]/f[i-1]*sum[j-1]+(g[i]-g[i-1])/f[i-1]

y     =     k     *       x       +              b

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define max(a,b) (a>b?a:b)
#define ll long long
const int maxn=2000010,inf=(int)1e9;
const double eps=1e-9;
using namespace std;
int n,m,sum[maxn],f[maxn],t[maxn],q[maxn],top;ll tim,g[maxn];char ch;
for (ch=getchar();!isdigit(ch);ch=getchar());
for (x=0;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
}

double slope(int i,int j){
if (i==0||j==0) return inf;
if (i==inf||j==inf) return -inf;
return 1.0*(sum[i]-sum[j])/(double)(sum[i-1]-sum[j-1]);
}

void work(){
q[1]=0,q[2]=1,top=2,q[top+1]=inf,g[1]=0;
for (int i=2;i<=n;i++){
for (;top&&slope(i,q[top])>slope(q[top],q[top-1])+eps;) {
top--;
}
q[++top]=i,q[top+1]=inf;
}
for (int i=2;i<=m;i++){
int l=1,r=top,mid=(l+r)>>1;double k=(1.0*f[i])/(1.0*f[i-1]);
while (1){
if (slope(q[mid],q[mid-1])+eps>=k&&slope(q[mid],q[mid+1])<=k+eps) break;
else if (slope(q[mid],q[mid+1])>k+eps) l=mid+1;
else r=mid-1;
mid=(l+r)>>1;
}
g[i]=g[i-1]+(ll)sum[q[mid]]*f[i-1]-(ll)sum[q[mid]-1]*f[i];
}
printf("%lld\n",1ll*(g[m]+1ll*sum[n]*f[m]));
}

int main(){
freopen("yume.in","r",stdin);freopen("yume.out","w",stdout);
work();
fclose(stdout);
return 0;
}

#### 2018SD省队集训R1 D3

2018-06-12 21:54:21

#### SDOI2016第一轮省队集训

2016-05-30 21:23:48

#### 2018SD省队集训R1 D4

2018-06-12 22:11:35

#### 2018年一轮省队集训Day2 - 多项式 - 拉格朗日插值 - 容斥原理

2018-06-10 21:46:39

#### 2018SD省队集训R1 D6

2018-06-17 23:36:04

#### 2018SD省队集训R1 D7

2018-06-19 21:36:27

#### 2018SD省队集训R1 D5

2018-06-13 20:19:56

#### [HN省队集训Day2]有趣的字符串题　回文树＋线段树＋树状数组

2018-06-21 20:16:28

#### NOI2018湖北省队集训Day3 T1 贪婪人

2018-05-23 18:35:00

#### 湖南集训 Day2

2017-10-17 14:56:44