RT,题解区基本上都是斜优
帮调过送2关
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<unordered_map>
#include<vector>
#include<queue>
#include<bitset>
#include<set>
#include<ctime>
#include<random>
#define x1 xx1
#define y1 yy1
#define IOS ios::sync_with_stdio(false)
#define ITIE cin.tie(0);
#define OTIE cout.tie(0);
#define PY puts("Yes")
#define PN puts("No")
#define PW puts("-1")
#define popcount __builtin_popcount
#define int long long
using namespace std;
inline int R(){
int x=0,f=1;int ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}return x*f;
}
inline void write(int x){
if(x<0){x=-x;putchar('-');}
int y=0;char z[70];
while(x||!y){z[y++]=x%10+48;x/=10;}
while(y--)putchar(z[y]);
}
inline void writesp(int x){
write(x);putchar(32);
}
inline void writeln(int x){
write(x);putchar(10);
}
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define reprange(a,b,c,d) for(int a=b;a<=c;a+=d)
#define perrange(a,b,c,d) for(int a=b;a>=c;a-=d)
#define graph(i,j,k,l) for(int i=k[j];i;i=l[i].nxt)
#define lowbit(x) (x&-x)
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
const int maxn=5e4+5,maxk=1e6+5;
int n,m,l[maxn],w[maxn];
int a[maxn],c[maxn];//a是宽c是长
int b[maxk];
int f[maxn];
int sta[maxn],tp;
int lft[maxn];
int calc(int x,int y){
return f[x]+a[x+1]*c[y];
}
int find(int x){//找到x所属的决策
int l=1,r=tp;
while(l<r){
int mid=l+r+1>>1;
if(lft[sta[mid]]<x) l=mid;
else r=mid-1;
}
return sta[l];
}
signed main(){
m=R();rep(i,1,m) l[i]=R(),w[i]=R();
rep(i,1,m) b[l[i]]=max(b[l[i]],w[i]);
per(i,1e6,1) if(b[i]>a[n]) a[++n]=b[i],c[n]=i;
reverse(a+1,a+n+1);
reverse(c+1,c+n+1);
// rep(i,1,n) printf("%d %d\n",c[i],a[i]);
sta[++tp]=0;lft[0]=1;
rep(i,1,n){
f[i]=calc(find(i),i);
while(tp&&lft[sta[tp]]>i&&calc(i,lft[sta[tp]])<calc(sta[tp],lft[sta[tp]])) tp--;
int l=lft[sta[tp]],r=n;
while(l<r){
int mid=l+r>>1;
if(calc(i,mid)<calc(sta[tp],mid)) r=mid;
else l=mid+1;
}
if(calc(i,l)<calc(sta[tp],l)){
sta[++tp]=i;
lft[i]=l;
}
}
write(f[n]);
}