Pagini recente » Cod sursa (job #83334) | Cod sursa (job #159593) | Cod sursa (job #2714952) | Cod sursa (job #1178576) | Cod sursa (job #2174717)
#include <iostream>
#include <fstream>
using namespace std;
#define nmax 100005
ifstream f("scmax.in");
ofstream g("scmax.out");
int n,el[nmax],maxseq=1,indice[nmax],tata[nmax];
void read()
{
f>>n;
for (int i=1; i<=n; ++i)
f>>el[i];
}
void tati(int curent)
{
if (curent)
{
tati(tata[curent]);
g<<el[curent]<<' ';
}
}
void afis()
{
g<<maxseq<<'\n';
tati(indice[maxseq]);
}
void solve()
{
indice[1]=1;
for (int i=2; i<=n; ++i)
{
int left=0,right=maxseq;
while (left<=right)
{
int mid=(left+right)/2;
if (el[i]>el[indice[mid]])
left=mid+1;
else
right=mid-1;
}
if (left>maxseq)
maxseq=left;
indice[left]=i;
tata[i]=indice[left-1];
}
afis();
}
int main()
{
read();
solve();
return 0;
}