提交时间:2021-12-11 21:42:19
运行 ID: 34520
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=100010; inline ll read(); inline void write(ll x); inline void writeln(ll x); int n,cnt=0; ll dp[N]; struct aa { ll x,y; } field[N],work[N]; inline bool operator<(const aa &a,const aa &b) { if(a.x!=b.x) return a.x<b.x; return a.y<b.y; } inline ll read() { ll s=0; bool flag=false; char ch=getchar(); for(; ch<'0'||ch>'9'; ch=getchar()) if(ch=='-') flag=true; for(; '0'<=ch&&ch<='9'; ch=getchar()) s=(s<<3)+(s<<1)+(ch^48); if(flag) return -s; return s; } inline void write(ll x) { if(!x) { putchar('0'),putchar(' '); return ; } if(x<0) putchar('-'),x=-x; char ch[20]; int tot=0; while(x) ch[++tot]=x%10,x/=10; for(int i=tot; i; i--) putchar(ch[i]^48); putchar(' '); } inline void writeln(ll x) { write(x); putchar('\n'); } int main() { n=read(); for(int i=1; i<=n; i++) field[i].x=read(),field[i].y=read(); sort(field+1,field+n+1); for(int i=1; i<=n; i++) { while(cnt&&field[i].y>=work[cnt].y) cnt--; work[++cnt]=field[i]; } n=cnt; memset(dp,0x3f,sizeof(dp)); dp[0]=0; for(int i=1; i<=n; i++) { for(int j=1; j<=i; j++) { dp[i]=min(dp[i],dp[j-1]+work[i].x*work[j].y); } } writeln(dp[n]); return 0; }