Pagini recente » Cod sursa (job #2616368) | Cod sursa (job #2589759) | Cod sursa (job #1140927) | Cod sursa (job #1515341) | Cod sursa (job #1466086)
#include <iostream>
#include <fstream>
#define fin "scmax.in"
#define fou "scmax.out"
using namespace std;
ifstream t1(fin);
ofstream t2(fou);
int n,prec[100010],best[100010],maxim,pozmax;
long sir[100010];
int main()
{
int i,j;
t1>>n;
for(i=1;i<=n;i++) t1>>sir[i];
best[n]=1; prec[n]=0; maxim=1;
for(i=n-1;i>=1;i--)
{
best[i]=1;
prec[i]=0;
for(j=i+1;j<=n;j++)
if(best[j]+1>best[i] && sir[j]>sir[i])
{
best[i]=best[j]+1;
prec[i]=j;
if(best[i]>maxim)
{
maxim=best[i];
pozmax=i;
}
}
}
t2<<maxim<<'\n';
while(prec[pozmax])
{
t2<<sir[pozmax]<<' ';
pozmax=prec[pozmax];
}
t2<<sir[pozmax]<<'\n';;
t1.close();
t2.close();
return 0;
}