Pagini recente » Cod sursa (job #1291022) | Cod sursa (job #2978910) | Cod sursa (job #2562226) | Cod sursa (job #2654204) | Cod sursa (job #2474756)
#include <bits/stdc++.h>
#define Dim 100001
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int N,V[Dim],Q[Dim],L[Dim],lg,st,dr,gasit_poz,cnt,copie;
int Afis[Dim],again;
int main()
{
f>>N;
for(int i=1;i<=N;i++) f>>V[i];
for(int i=1;i<=N;i++)
{
st=1; dr=lg;
bool ok=0;
while(st<=dr)
{
int mij=(st+dr)/2;
if( V[ i ] > Q[ mij ] ) st=mij+1;
else
{
gasit_poz=mij;
ok=1;
dr=mij-1;
}
}
if( ok )
{
Q[ gasit_poz ] = V[ i ] ;
L[ ++cnt ] = gasit_poz;
}
else
{
Q[ ++lg ] = V[ i ] ;
cnt++;
L[ cnt ] = lg;
}
}
g<<lg<<'\n';
copie=lg;
for(int i=cnt;i >= 1 && copie > 0 ;i--)
if( L[ i ] == copie )
{
copie--;
Afis[++again]=i;
}
for(int i=again;i>=1;i--) g<<V[ Afis[ i ] ]<<" ";
return 0;
}