还是模拟队列看着清爽啊
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long LL;
const int maxn = 50005;
int q[maxn];
LL w[maxn],h[maxn];
vector<pii> ve;
LL dp[maxn];
int main(){
int n;
LL x,y;
scanf("%d",&n);
for( int i = 1;i <= n;i++ )scanf("%lld%lld",&x,&y),ve.push_back(pii(x,y));sort( ve.begin(),ve.end() );
int tot = 0;
for( int i = 0;i < ve.size();i++ ){
while(tot&&ve[i].second >= h[tot]) tot--;
h[++tot] = ve[i].second;w[tot] = ve[i].first;
}
int l = 0,r = 0;
for( int i = 1;i <= tot;i++ ){
while( l < r && dp[q[l+1]]-dp[q[l]] < -1LL*w[i]*( h[ q[l+1]+1 ]-h[ q[l]+1 ] ) )l++;
dp[i] = dp[ q[l] ] + 1LL*w[i]*h[ q[l]+1 ];
while( l<r && (dp[i]-dp[ q[r] ]) *( h[ q[r]+1 ]-h[ q[r-1]+1 ] ) > (dp[ q[r] ]-dp[ q[r-1] ])*( h[i+1]-h[ q[r]+1 ] ) )r--;
q[++r] = i;
}
printf("%lld",dp[tot]);
return 0;
}