# bzoj1597 [Usaco2008 Mar]土地购买

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 50050
#define ll long long
inline ll rd()
{
ll f=1,c=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){c=10*c+ch-'0';ch=getchar();}
return f*c;
}
ll n,m;
struct Pair
{
ll a,b;
}p0[N],p[N];
bool cmp(Pair x,Pair y)
{
if(x.a!=y.a)return x.a>y.a;
return x.b>y.b;
}
ll dp[N];
struct wsx
{
ll x,y;
wsx(){}
wsx(ll x,ll y):x(x),y(y){}
}sta[N];
double slop(wsx a,wsx b)
{
return (double)(a.y-b.y)/(a.x-b.x);
}
int tl;
int fd(ll k)
{
int l=1,r=tl-1,ans=tl;
while(l<=r)
{
int mid = (l+r)>>1;
if((sta[mid+1].y-sta[mid].y)>k*(sta[mid+1].x-sta[mid].x))
{
ans = mid;
r = mid-1;
}else l = mid+1;
}
return ans;
}
int main()
{
//  freopen("tt.in","r",stdin);
n = rd();
for(int i=1;i<=n;i++)
p0[i].a=rd(),p0[i].b=rd();
sort(p0+1,p0+1+n,cmp);
ll max_b = -1;
for(int i=1;i<=n;i++)
{
if(p0[i].b>max_b)
{
max_b = p0[i].b;
p[++m] = p0[i];
}
}
sta[++tl] = wsx(-p[1].a,0);
for(int i=1;i<=m;i++)
{
int now = fd(p[i].b);
dp[i] = sta[now].y - sta[now].x*p[i].b;
wsx tmp = wsx(-p[i+1].a,dp[i]);
while(tl>=1&&slop(sta[tl],sta[tl-1])>=slop(sta[tl],tmp))tl--;
sta[++tl]=tmp;
}
printf("%lld\n",dp[m]);
return 0;
}

posted @ 2019-01-04 09:44  LiGuanlin  阅读(104)  评论(0编辑  收藏  举报