-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathComposing Pyramids.cpp
52 lines (52 loc) · 1.13 KB
/
Composing Pyramids.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
49
50
51
52
#include <iostream>
#include <cmath>
#include <map>
using namespace std;
#define speed() \
ios::sync_with_stdio(false); \
cin.tie(0)
#define piss(name) \
speed(); \
freopen(#name "in.txt","r",stdin); \
freopen(#name "out.txt","w",stdout)
#define ll long long
#define umap std::unordered_map
#define ummap std::unordered_multimap
#define uset std::unordered_set
#define umset std::unordered_multiset
#define mmap std::multimap
#define mset std::multiset
int main()
{
piss(comp);
int n;cin>>n;
int pyr[n];
for (int i=0;i<n;i++){
int iv;cin>>iv;
pyr[i]=iv;
}
int lreq[100001]{0};
int rreq[100001]{0};
int bcl[n],bcr[n];
for (int i=0;i<n;i++){
lreq[pyr[i]]=lreq[pyr[i]-1]+1;
bcl[i]=lreq[pyr[i]];
}
for (int i=0;i<n;i++){
rreq[pyr[n-1-i]]=rreq[pyr[n-1-i]-1]+1;
bcr[i]=rreq[pyr[n-1-i]];
}
/*for (int i=0;i<n;i++){
cout<<bcl[i]<<'\t';
}
cout<<'\n';
for (int i=0;i<n;i++){
cout<<bcr[i]<<'\t';
}
cout<<'\n';*/
int cr=0;
for (int i=0;i<n;i++){
cr=max(cr,min(bcl[i],bcr[n-1-i]));
}
cout<<n-(cr*2-1)<<'\n';
}