Pagini recente » Cod sursa (job #2393233) | Cod sursa (job #2741278) | Profil Justinelu1998 | Istoria paginii runda/agm2 | Cod sursa (job #1536141)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("scmax.in");
ofstream g ("scmax.out");
long best[100003],a[100003], maxx,sol=0,poz[100003],p,n;
void citire()
{
f>>n;
for (int i=1; i<=n; i++) f >> a[i];
}
int main()
{
citire();
int i,j;
best[n]=1;
poz[n]=-1;
maxx=1;
p=n;
for(i=n-1; i>=1; --i)
{
best[i]=1;
poz[i]=-1;
for(j=i+1; j<=n; ++j)
if(a[j]>a[i] && best[i]<best[j]+1)
{
best[i]=best[j]+1;
poz[i]=j;
if(best[i]>maxx) maxx=best[i],p=i;
}
}
i=p;
g << maxx << "\n";
while(i!=-1)
{
g << a[i] << " ";
i=poz[i];
}
return 0;
}