Pagini recente » Cod sursa (job #683278) | Cod sursa (job #2436200) | Cod sursa (job #2487525) | Cod sursa (job #192857) | Cod sursa (job #2183096)
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
const int nmax=100005;
int n, maxi, p;
int a[nmax], poz[nmax], l[nmax];
void read()
{
int i;
fin>>n;
for(i=1;i<=n;i++)
fin>>a[i];
}
void solve()
{
int i, j;
for(i=n;i>=1;i--)
{
l[i]=1;
poz[i]=-1;
for(j=i+1;j<=n;j++)
if(a[j]>a[i] && l[i]<l[j]+1)
{
l[i]=l[j]+1;
poz[i]=j;
}
if(l[i]>maxi)
{
maxi=l[i];
p=i;
}
}
}
void print()
{
int i;
fout<<maxi<<'\n';
i=p;
while(i!=-1)
{
fout<<a[i]<<' ';
i=poz[i];
}
}
int main()
{
read();
solve();
print();
}