Pagini recente » Cod sursa (job #288161) | Cod sursa (job #354162) | Cod sursa (job #311657) | Cod sursa (job #2412320) | Cod sursa (job #1971601)
#include <iostream>
#include <fstream>
using namespace std;
#define in "scmax.in"
#define out "scmax.out"
#define N 100005
ifstream f(in);
ofstream g(out);
long best[N], a[N], n, i, j, maxi;
void afisare(int I, int Maxi)
{
if(I>=1 && best[I]==Maxi)
{
afisare(I-1,Maxi-1);
g<<a[I]<<' ';
}
else if(I>=1)
afisare(I-1,Maxi);
}
int main ()
{
f>>n;
for(i=1; i<=n; i++)
f>>a[i];
for(i=1; i<=n; i++)
{
best[i]=1;
j=i-1;
while(j>=1&&best[j]<=maxi)
{
if(a[j]<a[i])
best[i]=max(best[i],best[j]+1);
j--;
}
maxi=max(best[i],maxi);
}
// for(int i=1; i<=n; i++)
// cout<<best[i]<<' ';
g<<maxi;
g<<'\n';
afisare(n,maxi);
g<<'\n';
f.close();
g.close();
return 0;
}