Pagini recente » Cod sursa (job #1647688) | Cod sursa (job #2916702) | Cod sursa (job #2531558) | Cod sursa (job #1250742) | Cod sursa (job #1164559)
#include<stdio.h>
#define nmax 100005
struct element{int nr,poz;};
int st, dr, mjc, ne, n, x, poz, i, rez, vrez[nmax], prez, an[nmax], nr, a[nmax];
element v[nmax];
void cauta()
{
st=1; dr=ne;
while (st<=dr)
{
mjc=(st+dr)/2;
if (v[mjc].nr<x)
st=mjc+1;
else
dr=mjc-1;
}
poz=st;
if(poz>ne)
ne++;
}
int main()
{
freopen("scmax.in","r",stdin);
freopen("scmax.out","w",stdout);
scanf("%ld",&n);
for (i=1;i<=n;i++)
{
scanf("%ld",&x);
cauta();
v[poz].nr=x; v[poz].poz=i; an[i]=v[poz-1].poz;
if (poz>rez)
{ rez=poz; prez=i; }
a[i]=x;
}
printf("%ld\n",rez);
x=prez;
while (x)
{
vrez[++nr]=x;
x=an[x];
}
for (i=rez;i>=1;i--)
printf("%ld ",a[vrez[i]]);
return 0;
}