Pagini recente » Cod sursa (job #1610216) | Cod sursa (job #1797031) | Cod sursa (job #750732) | Cod sursa (job #1895038) | Cod sursa (job #2291799)
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <climits>
using namespace std;
void beolvas(int *&t, int &n)
{
freopen("scmax.in", "r", stdin);
freopen("scmax.out", "w", stdout);
cin>>n;
t = (int *)malloc((n+1)*sizeof(int));
for(int i = 1; i<=n; i++)
cin>>t[i];
t[0] = 0;
}
int main()
{
int *t, n, *temp, MAX, maxh;
beolvas(t,n);
temp = (int *)calloc(n+1,sizeof(int));
temp[n] = 1;
for(int i = n-1; i>=0; i--)
{
MAX = INT_MIN;
for(int j = i; j<=n; j++)
{
if(t[i]<t[j])
if(temp[j]>MAX)
MAX = temp[j];
}
temp[i] = MAX + 1;
}
cout<<temp[0]-1<<endl;
int a = temp[0]-1;
for(int i = 1; i<=n; i++)
{
if(temp[i] == a)
{
cout<<t[i]<<' ';
a--;
}
}
free(temp);
free(t);
return 0;
}