Pagini recente » Cod sursa (job #2191187) | Cod sursa (job #2610548) | Cod sursa (job #1010906) | Cod sursa (job #1171196) | Cod sursa (job #1464761)
#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--)
for(j=i+1;j<=n;j++)
if(best[j]>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;
}