Pagini recente » Cod sursa (job #2669918) | Cod sursa (job #2737677) | Cod sursa (job #2065548) | Cod sursa (job #46658) | Cod sursa (job #553266)
Cod sursa(job #553266)
#include<iostream>
#include<stdio.h>
using namespace std;
int t[100001], l[100001],v[100001] ,bien, poz, n;
void lire()
{
int i;
scanf("%d",&n);
for( i=1; i<=n; i++ )
scanf("%d",&v[i]);
}
void solve()
{
int i,j;
t[0] = v[1]; bien++; l[1] = 1;
for( i=2; i<=n; i++ )
{
bool ok = true;
for( j=0; j<bien && ok ; j++ )
if( v[i]<t[j] )
{
ok = false;
t[j] = v[i];
l[i] = j+1;
}
else if( v[i]==t[j] ) ok = false;
if( ok )
t[bien++] = v[i],
l[i] = bien;
}
}
void afish()
{
int i,j=0;
printf("%d\n",bien);
while(n)
{
if(l[n]==bien)
t[j++] = v[n],
bien--;
n--;
}
while(j--) printf("%d ",t[j]);
}
int main()
{
freopen("scmax.in","r",stdin);
freopen("scmax.out","w",stdout);
lire();
solve();
afish();
return 0;
}