Pagini recente » Cod sursa (job #2969895) | Cod sursa (job #2134728) | Cod sursa (job #1467031) | Cod sursa (job #1333939) | Cod sursa (job #1467279)
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <time.h>
#include <bitset>
#include <string>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <limits.h>
#include <algorithm>
#include <deque>
#define nmax 100010
using namespace std;
int n,i,t[nmax],b[nmax],v[nmax],j,vv;
inline int max(int a,int b) { if (a>b) return a; else return b; }
int cauta(int x,int st,int dr)
{
int m;
while (st<=dr) {
m=(st+dr)/2;
if (v[m]<x) st=m+1; else dr=m-1;
}
return st;
}
int main() {
freopen("scmax.in","r",stdin);
freopen("scmax.out","w",stdout);
scanf("%d",&n);
for (i=1;i<=n;i++) scanf("%d",&t[i]);
b[1]=1; vv=1; v[1]=t[1];
for (i=2;i<=n;i++) {
j=cauta(t[i],1,vv); b[i]=j;
v[j]=t[i]; vv=max(vv,j);
}
printf("%d\n",vv); j=vv;
for (i=n;i>=1;i--)
if (b[i]==j) { v[j]=t[i]; j--; }
for (i=1;i<=vv;i++) printf("%d ",v[i]);
return 0;
}