-
Notifications
You must be signed in to change notification settings - Fork 0
/
luogu1091.cpp
48 lines (47 loc) · 956 Bytes
/
luogu1091.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
bool cmp(int a,int b){
return a>b;
}
int main(){
int a[100000],f[100000]={0},b[100000]={0};
int n=0,ans1=0,ans2=0,maxn=0,ll=0;
int len=1;
while(cin>>a[n])n++;
ll=n;
for(int j=1;j<=ll;j++){
len=1;
f[0]=a[0];
for(int i=1;i<n;i++){
if(a[i]<=f[len-1]) len++,f[len-1]=a[i];
else {
int pos;
pos=upper_bound(f,f+len,a[i],cmp)-f;
f[pos]=a[i];
}
}
ans1=len;
// cout<<len<<'\n';
memset(f,0,sizeof(f));
len=1;
f[1]=b[0];
for(int i=1;i<n;i++){
if(b[i]>f[len]) f[++len]=b[i];
else {
int pos;
pos=lower_bound(f,f+len,b[i])-f;
f[pos]=b[i];
}
}
if(b[0]==0&&len==1)len=0;
ans2=len;
maxn=max(maxn,ans1+ans2);
b[ll-n]=a[n];
a[n]=0;
n--;
}
//cout<<len;
cout<<ll-maxn;
}