Pagini recente » Cod sursa (job #2090260) | Cod sursa (job #3149651) | Cod sursa (job #59851) | Cod sursa (job #2682660) | Cod sursa (job #2291812)
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <climits>
using namespace std;
int main()
{
int *t, n, *temp, MAX, maxh;
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;
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];
}
if(MAX == INT_MIN)
temp[i] = 1;
else
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;
}