Pagini recente » Cod sursa (job #2817019) | Cod sursa (job #1855420) | Cod sursa (job #550157) | Cod sursa (job #1380790) | Cod sursa (job #2483002)
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
long long int n,v[100010],poz[100010], best[100010], p, maxn;
int main()
{
fin>>n;
for (int i=1; i<=n; i++) fin>>v[i];
best[n]=1;
poz[n]=-1;
p=n;
maxn=1;
for (int i=n-1; i>=1; i--)
{
best[i]=1;
poz[i]=-1;
for (int j=i+1; j<=n; j++)
{
if (v[i]<v[j] && best[i]<best[j]+1)
{
best[i]=best[j]+1;
poz[i]=j;
if (best[i]>maxn) {maxn=best[i]; p=i;}
}
}
}
fout<<maxn<<endl;
int i=p;
while (i!=-1)
{
fout<<v[i]<<" ";
i=poz[i];
}
return 0;
}