显然f[i]=min(f[j]+y[j+1]x[i]),然后再搞个斜率优化,方程是(f[j]-f[k])/(y[k+1]-y[j+1])<x[i],然后维护一个下凸包!
1 #include <bits/stdc++.h>
2 using namespace std;
3 inline int read()
4 {
5 int x=0,f=1;
6 char ch=getchar();
7 while(ch<‘0‘||ch>‘9‘)
8 {
9 if(ch==‘-‘)
10 f=-1;
11 ch=getchar();
12 }
13 while(ch>=‘0‘&&ch<=‘9‘)
14 {
15 x=x*10+ch-‘0‘;
16 ch=getchar();
17 }
18 return x*f;
19 }
20 typedef long long ll;
21 int n,tot;
22 const int N=50050;
23 ll x[N],y[N],f[N];
24 int q[N];
25 struct data
26 {
27 ll x,y;
28 }a[N];
29 inline bool cmp(data a,data b)
30 {
31 return a.x==b.x?a.y<b.y:a.x<b.x;
32 }
33 inline double slop(int a,int b)
34 {
35 return (double)(f[b]-f[a])/(y[a+1]-y[b+1]);
36 }
37 int main()
38 {
39 n=read();
40 for(int i=1;i<=n;i++)
41 {
42 a[i].x=read();
43 a[i].y=read();
44 }
45 sort(a+1,a+1+n,cmp);
46 for(int i=1;i<=n;i++)
47 {
48 while(tot&&a[i].y>=y[tot])
49 tot--;
50 x[++tot]=a[i].x;
51 y[tot]=a[i].y;
52 }
53 int l=0,r=0;
54 for(int i=1;i<=tot;i++)
55 {
56 while(l<r&&slop(q[l],q[l+1])<x[i])
57 l++;
58 int t=q[l];
59 f[i]=f[t]+y[t+1]*x[i];
60 while(l<r&&slop(q[r],i)<slop(q[r-1],q[r]))
61 r--;
62 q[++r]=i;
63 }
64 printf("%lld\n",f[tot]);
65 return 0;
66 }