# BZOJ 1609: [Usaco2008 Feb]Eating Together麻烦的聚餐【最长升降】

## 1609: [Usaco2008 Feb]Eating Together麻烦的聚餐

Time Limit: 10 Sec Memory Limit: 64 MB

Description

Input

Output

Sample Input

5
1
3
2
1
1

Sample Output

1

#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[30005],Now,Ans,f[30005],que[30005];
bool cmp(int x,int y){return x>y;}
void Fnd(int x){
int L=1,R=Now;
while(L<=R){
int mid=(R+L)>>1;
if(que[mid-1]<=x&&x<que[mid]){que[mid]=x;return;}
if(x>que[mid]) R=mid-1;else L=mid+1;
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("prob.in","r",stdin);
freopen("prob.out","w",stdout);
#endif
scanf("%d",&n);Now=0;
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
if(a[i]>=que[Now]) que[++Now]=a[i];
else Fnd(a[i]);
Ans=max(Now,Ans);Now=0;
for(int i=1;i<=n/2;i++) swap(a[i],a[n-i+1]);
for(int i=1;i<=n;i++)
if(a[i]>=que[Now]) que[++Now]=a[i];
else Fnd(a[i]);
Ans=max(Now,Ans);
printf("%d\n",n-Ans);
return 0;
}
posted @ 2018-05-14 21:36  XSamsara  阅读(106)  评论(0编辑  收藏  举报