Pagini recente » Cod sursa (job #2738788) | Cod sursa (job #507078) | Cod sursa (job #2462319) | Cod sursa (job #3199194) | Cod sursa (job #2180679)
#include <fstream>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
int i, poz,n,v[100],b[100],r[100],p,maxx;
int constr(int poz)
{int maxi=0;
if(poz==1)return 1;
for(i=1;i<poz;i++)
if(v[i]<v[poz]&&b[i]>maxi)
maxi=b[i];
return maxi+1;
}
int solutie(int &maxi)
{
for(i=maxi-1;i>=1;i--)
if(b[i]==b[maxi]-1)
{maxi=i;return v[i];}
}
int main()
{int maxi=0;
in>>n;
for(i=1;i<=n;i++)
in>>v[i];
for(i=1;i<=n;i++)
b[i]=constr(i);
for(i=1;i<=n;i++)
if(b[i]>maxi)
{maxi=b[i]; maxx=i;}
r[++p]=v[maxx];
int aux=maxx-1;
for(i=aux;i>=1;i--)
{r[++p]=solutie(maxx);}
out<<p<<'\n';
for(i=p;i>=1;i--)
out<<r[i]<<" ";
return 0;
}