Pagini recente » Cod sursa (job #1534702) | Cod sursa (job #1357006) | Cod sursa (job #2896533) | Cod sursa (job #1858017) | Cod sursa (job #1334241)
#include <cstdio>
using namespace std;
FILE *f1,*f2;
int n,a[100001],t[100001],s[100001],i,j,max1,p;
int main()
{f1 = fopen("scmax.in","r");
f2 = fopen("scmax.out","w");
fscanf(f1,"%d",&n);
for (i=1;i<=n;i++) fscanf(f1,"%d",&a[i]);
s[n]=1;
for (i=n-1;i>=1;i--)
{max1=0;
for (j=i+1;j<=n;j++)
if (a[i]<a[j] && s[j]>max1) {max1=s[j];p=j;}
s[i]=max1+1;
if (max1==0) t[i]=0;
else t[i]=p;
}
max1=0;
for (i=1;i<=n;i++) if (s[i]>max1) {max1=s[i];p=i;}
fprintf(f2,"%d\n",max1);
while (p!=0) {fprintf(f2,"%d ",a[p]);p=t[p];}
fclose(f1);fclose(f2);
return 0;
}
//Challenges are what make life interesting and overcoming them is what makes life meaningful.