Pagini recente » Cod sursa (job #2748169) | Cod sursa (job #1619462) | Cod sursa (job #3170873) | Cod sursa (job #3173413) | Cod sursa (job #2573696)
#include <bits/stdc++.h>
#include <cstring>
# define pb push_back
#define nmax 100002
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
string a,b;
int ok,k,i,n,best[nmax],j,max1,urm[nmax],poz,v[nmax];
int main()
{
f>>n;
for(i=1;i<=n;i++)
f>>v[i];
best[n]=1;
for(i=n-1;i>=1;i--)
for(j=i+1;j<=n;j++)
if(v[i]<v[j])
{ if(best[i]<best[j]+1)
{
best[i]=best[j]+1;
if(best[i]>max1)
{
max1=best[i];
poz=i;
}
urm[i]=j;
}
}
g<<best[poz]<<"\n";
while(poz)
{
g<<v[poz]<<" ";
poz=urm[poz];
}
return 0;
}