Pagini recente » Cod sursa (job #2653036) | Cod sursa (job #1131159) | Cod sursa (job #2447494) | Cod sursa (job #293059) | Cod sursa (job #2639912)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
int v[100001], p[100001], s[100001], best[100001];
int n, ns=1, poz;
int bins(int x)
{
int i, step=1;
while(step<ns) step<<=1;
for(i=0; step; step>>=1)
if(step+i<=ns && v[s[step+i]]<x)
i+=step;
return i;
}
int main()
{
in>>n;
s[1]=best[1]=1;
for(int i=1; i<=n; i++) in>>v[i];
for(int i=2; i<=n; i++)
{
poz=bins(v[i]);
p[i]=s[poz];
best[i]=poz+1;
s[poz+1]=i;
if(poz+1>ns) ns=poz+1;
}
int ind=1;
for(int i=2; i<=n; i++)
if(best[i]>best[ind]) ind=i;
ns=1;
out<<best[ind]<<'\n';
while(ind) s[ns++]=v[ind], ind=p[ind];
for(int i=ns-1; i; i--) out<<s[i]<<' ';
return 0;
}