-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathscm.cpp
39 lines (36 loc) · 849 Bytes
/
scm.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
# include <bits/stdc++.h>
# define NR 100005
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int i,j,n,m,ci,cs,VV,poz,I,ant,mij,nrsol;
int a[NR], st[NR], L[NR], sol[NR];
int main ()
{
f>>n;
for (i=1; i<=n; ++i)
f>>a[i];
for (i=1; i<=n; ++i) {
if (a[i] > st[VV]) st[++VV]=a[i], L[i]=VV;
else {
ci=1; cs=VV;
while (ci<=cs) {
mij=(ci + cs)/2;
if (a[i]<=st[mij]) cs=mij-1, poz=mij;
else ci=mij+1;
}
st[poz]=a[i]; L[i]=poz;
}
}
I=VV+1; ant=st[VV]+1;
for (i=n; i>=1; --i) {
if (L[i]==I-1 && ant > a[i]) {
--I; sol[I]=a[i];
ant=a[i];
}
}
g<<VV<<"\n";
for (i=1; i<=VV; ++i)
g<<sol[i]<<" ";
return 0;
}