Pagini recente » Cod sursa (job #2422602) | Cod sursa (job #2972150) | Cod sursa (job #199204) | Cod sursa (job #3173305) | Cod sursa (job #2468369)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
#define nmax 100005
int n;
int vec[nmax],father[nmax],lung=0,poz_prec[nmax],new_vec[nmax],poz_act[nmax];
int caut_bin(int x){
int mid,lo=1,hi=lung;
while(hi-lo>1){
mid=(lo+hi)/2;
if(new_vec[mid]>=x and new_vec[mid-1]<x){
return mid;
}
if(new_vec[mid]>x){
hi=mid-1;
}
else{
lo=mid+1;
}
}
return lo;
}
void afisare_rec(int poz){
if(poz!=0){
afisare_rec(father[poz]);
g<<vec[poz]<<" ";
}
}
int main()
{
int poz;
f>>n;
for(int i=1;i<=n;i++){
f>>vec[i];
}
for(int i=1;i<=n;i++){
if(vec[i]>new_vec[lung]){
lung++;
new_vec[lung]=vec[i];
father[i]=poz_act[lung-1];
poz_act[lung]=i;
}
else{
poz=caut_bin(vec[i]);
new_vec[poz]=vec[i];
father[i]=poz_act[lung-1];
poz_act[lung]=i;
}
}
g<<lung<<'\n';
afisare_rec(poz_act[lung]);
return 0;
}