Pagini recente » Istoria paginii runda/becreative28 | Statistici Luis Greve (jhcourt91gh) | Cod sursa (job #699630) | Cod sursa (job #2365338) | Cod sursa (job #700102)
Cod sursa(job #700102)
#include<iostream>
#include<fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int a[100100],best[100100],pre[100100],x[100100];
int main()
{int n,j,i,max,poz;
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
for(i=1;i<=n;i++)
{max=0;
best[i]=1;
for(j=i-1;j>=1;j--)
if(best[j]>=max && a[j]<a[i])
{max=best[j];
best[i]=1+max;
pre[i]=j;
}
}
max=0;
for(i=1;i<=n;i++)
if(best[i]>max)
{max=best[i];
poz=i;
}
g<<max<<endl;
i=1;
while(best[poz]>=1)
{x[i]=a[poz];
i++;
poz=pre[poz];
}
for(j=i-1;j>=1;j--)
g<<x[j]<<" ";
return 0;
}