Pagini recente » Cod sursa (job #1600404) | Cod sursa (job #3262819) | Cod sursa (job #1010555) | Cod sursa (job #2281077) | Cod sursa (job #2649713)
#include<bits/stdc++.h>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout("scmax.out");
int v[100002],d[100002],nd=1,poz[100002];
int cb (int st,int dr,int x)
{
int last=0,mij;
while (st<=dr){
mij=(st+dr)/2;
if (x<=v[d[mij]])
{
last=mij;
dr=mij-1;
}
else st=mij+1;
}
return last;
}
void reconst(int x)
{
if (x!=0)
{
reconst(poz[x]);
fout<<v[x]<<' ';
}
}
int main ()
{
int n,i;
fin>>n;
for (i=1;i<=n;++i)
fin>>v[i];
d[1]=1;
for (i=2;i<=n;i++)
if (v[i]>v[d[nd]])
{
d[++nd]=i;
poz[i]=d[nd-1];
}
else
{
int pozitie=cb(1,nd,v[i]);
d[cb(1,nd,v[i])]=i;
poz[i]=d[pozitie-1];
}
fout<<nd<<'\n';
reconst(d[nd]);
fout<<'\n';
return 0;
}