Pagini recente » Cod sursa (job #1205501) | Clasament hoata2 | Cod sursa (job #1396574) | Cod sursa (job #573716) | Cod sursa (job #1153654)
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream f("scmax.in");
ofstream g("scmax.out");
int n,best[100001],i,j,v[100001],max=1,poz[100001],p;
f>>n;
for(i=1;i<=n;i++)
f>>v[i];
best[n]=1;
poz[n]=-1;
for(i=n-1;i>=1;i--)
{
best[i]=1;
poz[i]=-1;
for(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]>max)
{
max=best[i];
p=i;
}
}
}
}
g<<max<<'\n';
i=p;
while(i!=-1)
{
g<<v[i]<<' ';
i=poz[i];
}
f.close();
g.close();
return 0;
}