#include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
struct data{
int x,y;
}a[50005];
int q[50005],l,r,tot,n;
long long x[50005],y[50005],f[50005];
inline bool cmp(data a,data b){
return a.x==b.x?a.y<b.y:a.x<b.x;
}
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return f*x;
}
inline double calc(int k,int j){
return (double)(f[j]-f[k])/(y[k+1]-y[j+1]);
}
int main(){
n=read();
for(int i=1;i<=n;i++){
a[i].x=read();a[i].y=read();
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++){
while(tot&&a[i].y>=y[tot])tot--;
x[++tot]=a[i].x;y[tot]=a[i].y;
}
for(int i=1;i<=tot;i++){
while(l<r&&calc(q[l],q[l+1])<x[i])l++;
int t=q[l];f[i]=f[t]+y[t+1]*x[i];
while(l<r&&calc(q[r],i)<calc(q[r-1],q[r]))r--;
q[++r]=i;
}
printf("%lld",f[tot]);
}
[Bzoj1597][Usaco2008 Mar]土地购买
最新推荐文章于 2018-03-28 10:12:59 发布