Pagini recente » Cod sursa (job #1057555) | Cod sursa (job #2374418) | Cod sursa (job #2032887) | Profil EugenStoica | Cod sursa (job #1083204)
#include <fstream>
#define MAX_N 100000
using namespace std;
int a[MAX_N]; // vector dat
int start[MAX_N];// start[i]= j unde a[j] este primul element dintr-un subsir crescator de lungime i;
int position[MAX_N];// position[i] = positia elementului dupa a[i] sau -1 daca nu exista
int N,Lmax,i;
int cautare(int first,int last, int value)
{
int middle;
while (p<=u)
{
middle=first+(last-first)/2;
if (x<a[start[middle])
first=middle+1;
else
last=middle-1;
}
return first;
}
int main()
{
ifstream f("scmax.in");
ofstream g("scmax.out");
f>>N;
for (i=0;i<N;i++)
f>>a[i];
for (int i=n-1;i>=0;i--)
{
position[i]=-1;
int lenght=cautare(0,Lmax,a[i]);// caut binar
if (lenght>Lmax)
{
position[i]=start[lenght];
Lmax=lenght;
start[lenght]=i;
}
else{
position[i]=start[lenght-1];
if (a[start[lenght]<a[i])
start[lenght]=i;
}
}
g<<Lmax<<"\n";
i=start[Lmax];
while (i>-1)
{
g<<a[i]<<" ";
i=position[i]
}
return 0;
}