# 思路

$f[i]=\min(f[j]+a_i\times b_{j+1})$

# 代码

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=50010,M=1000010;
int n,m,a[N],b[N],q[N];
ll f[N];

struct node
{
int a,b;
bool flag;
}c[N];

bool cmp(node x,node y)
{
if (x.a<y.a) return 1;
if (x.a>y.a) return 0;
return x.b<y.b;
}

int main()
{
scanf("%d",&m);
for (int i=1;i<=m;i++)
scanf("%d%d",&c[i].a,&c[i].b);
sort(c+1,c+1+m,cmp);
for (int i=m,maxn=0;i>=1;i--)
if (c[i].b<=maxn) c[i].flag=1;
else maxn=c[i].b;
for (int i=1;i<=m;i++)
if (!c[i].flag)
{
n++;
a[n]=c[i].a; b[n]=c[i].b;
}
int l=1,r=1;
for (int i=1;i<=n;i++)
{
for (int x=q[l],y=q[l+1];l<r;x=q[l],y=q[l+1])
if (l<r && f[y]-f[x]<=1LL*a[i]*(b[x+1]-b[y+1])) l++;
else break;
f[i]=f[q[l]]+1LL*a[i]*b[q[l]+1];
for (int x=q[r-1],y=q[r];l<r;x=q[r-1],y=q[r])
if (l<r && (f[y]-f[x])*(b[y+1]-b[i+1])>=(f[i]-f[y])*(b[x+1]-b[y+1])) r--;
else break;
q[++r]=i;
}
printf("%lld",f[n]);
return 0;
}
/*
4
100 1
15 15
20 5
1 100
*/

posted @ 2020-03-23 18:55  stoorz  阅读(47)  评论(0编辑  收藏