#include #include #include #include #include #include #include #include #include #define INF 1ll<<60 typedef long long LL; using namespace std; const int MAX=50000+10; int n,k,index,head,tail,Id; LL dp[MAX][2],q[MAX]; struct Node{ LL w,h; bool operator<(const Node &a)const{ return h>a.h; } }s[MAX]; LL GetY(int k,int k2){ return dp[k][index^1]-dp[k2][index^1]; } LL GetX(int k,int k2){ return s[k2+1].h-s[k+1].h; } void DP(){ index=0; memset(dp,0,sizeof dp); for(int i=1;i<=n;++i)dp[i][index]=INF; for(int j=1;j<=k;++j){ index=index^1; head=tail=0; q[tail++]=0; Id=0; for(int i=1;i<=n;++i){ if(s[i].w <= s[Id].w)continue; Id=i; while(head+1