Pagini recente » Cod sursa (job #1805807) | Cod sursa (job #2413030) | Cod sursa (job #3172235) | Cod sursa (job #1638016) | Cod sursa (job #2285387)
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
struct pair_compare {
bool operator() (const std::pair<int,int> & p1, const std::pair<int,int> & p2) const {
if(p1.first == p2.first)
return false;
else
return (p1.first < p2.first);
}
};
#define MAXN 100000
set<pair<int,int>,pair_compare> S;
int N;
int V[MAXN];
int B[MAXN];
int P[MAXN];
int main(){
freopen("scmax.in", "r", stdin);
freopen("scmax.out", "w", stdout);
scanf("%d",&N);
set<pair<int,int>,pair_compare>::iterator it;
int lung=1,pozbest=0;
for(int i=0;i<N;i++){
scanf("%d", &V[i]);
it=S.find(make_pair(V[i],0));
if(it==S.end())
S.insert(make_pair(V[i],i));
else
continue;
B[i]=1;
P[i]=-1;
for(it=S.begin();it->first<V[i];it++){
if((B[it->second]+1)>B[i]){
B[i]=B[it->second]+1;
P[i]=it->second;
}
}
if(B[i]>lung){
lung=B[i];
pozbest=i;
}
}
printf("%d\n",lung);
int lung1=lung;
int* pozitii=new int[lung];
while(pozbest!=-1){
lung--;
pozitii[lung]=pozbest;
pozbest=P[pozbest];
}
for(int i=0;i<lung1;i++)
printf("%d ",V[pozitii[i]]);
return 0;
}