Pagini recente » Cod sursa (job #152189) | Cod sursa (job #1294661) | Cod sursa (job #1497000) | Cod sursa (job #1364168) | Cod sursa (job #1649991)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
const int nmax = 1e5+5;
int dp[nmax], dad[nmax], v[nmax], maxx;
inline int bsearch(int val)
{
int st=1, dr=maxx, mij;
while(st<=dr)
{
mij=(st+dr)>>1;
if(v[dp[mij]] < val) st=mij+1;
else dr=mij-1;
}
return st;
}
void secventa(int nod)
{
if(dad[nod]) secventa(dad[nod]);
fout << v[nod] << " ";
}
int main()
{
ios_base::sync_with_stdio(false);
int n, i, poz;
fin >> n;
for(i=1; i<=n; i++)
fin >> v[i];
for(i=1; i<=n; i++)
{
poz=bsearch(v[i]);
maxx=max(maxx, poz);
dp[poz]=i;
dad[i]=dp[poz-1];
}
fout << maxx << "\n";
secventa(dp[maxx]);
fin.close();
fout.close();
return 0;
}