Pagini recente » Cod sursa (job #699724) | Cod sursa (job #2948627) | Cod sursa (job #815211) | Cod sursa (job #3174356) | Cod sursa (job #2118414)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int v[100001],pozmic[100001],pred[100001], n, m;
void subsir (int p)
{
if (pred[p]!=0)
subsir(pred[p]);
g<<v[p]<<" ";
}
int cautbin (int x)
{
int r=0,pas=1<<16;
while (pas!=0)
{
if (r+pas<=m && v[pozmic[r+pas]]<x)
r+=pas;
pas/=2;
}
return r;
}
int main()
{
int j,i;
f>>n;
m=0;
for (i=1;i<=n;i++)
f>>v[i];
for (i=1;i<=n;i++)
{
j=cautbin(v[i]);
pozmic[j+1]=i;
pred[i]=pozmic[j];
if (j==m)
{
m++;
}
}
g<<m<<"\n";
subsir(pozmic[m]);
return 0;
}