Cod sursa(job #1059905)
| Utilizator | Data | 17 decembrie 2013 10:42:15 | |
|---|---|---|---|
| Problema | Subsir crescator maximal | Scor | 70 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.68 kb |
#include<cstdio>
using namespace std;
int Lm,p,L[100001],a[100001],n,i;
void drum()
{
printf("%d\n",Lm);
int t;
t=0;p=1;
do
{
while (L[p]!=Lm || a[t]>a[p]) ++p;
printf("%d ",a[p]);
t=p;
--Lm;
}while (Lm);
}
int main()
{
freopen("scmax.in","r",stdin);
freopen("scmax.out","w",stdout);
scanf("%d",&n);
for (i=1;i<=n;++i) scanf("%d",&a[i]);
int j,Max;
L[n]=1;
for (i=n-1;i>=1;--i)
{
Max=0;
for (j=i+1;j<=n;++j)
if (L[j]>Max && a[i]<a[j])
Max=L[j];
L[i]=Max+1;
if (Lm<L[i]) Lm=L[i];
}
drum();
return 0;
}
