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