Pagini recente » Rating Costel Chites (costica123) | Cod sursa (job #355142)
Cod sursa(job #355142)
#include <fstream>
using namespace std;
ifstream fin("subsir.in");
ofstream fout("subsir.out");
int n, a[100], b[100];
void citire()
{
fin>>n;
for (int i=0;i <n; i++)
fin>>a[i];
}
void sir_nou()
{
int max;
for (int i=n-1; i>=0; i--)
{
max=0;
for (int j=i; j<n; j++)
if (a[i]<a[j] && b[j]>max)
max=b[j];
b[i]=max+1;
}
}
void afisare()
{
int max=0, imax=0;
for (int i=0; i<n; i++)
if (b[i]>max)
{
max=b[i];
imax=i;
}
fout<<max<<endl;
fout<<a[imax]<<" ";
int max1=max;
int x=a[imax];
for (int i=imax; i<n; i++)
if (b[i]==max1-1 && a[i]>x)
{
fout<<a[i]<<" ";
max1--;
x=a[i];
}
}
int main()
{
citire();
sir_nou();
afisare();
return 0;
}