Pagini recente » Cod sursa (job #2772254) | Cod sursa (job #2575111) | Cod sursa (job #972786) | Cod sursa (job #1139449) | Cod sursa (job #933441)
Cod sursa(job #933441)
#include<iostream>
#include<fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
long a[200000],aux[200000],b[200000],c=1,n;
int cautare(int x)
{
int p=1,q=c,m;
if(a[b[q]]<x) return q+1;
while(p<q)
{
m=(p+q)>>1;
if(a[b[m]]>=x) q=m;
else p=m+1;
}
return p;
}
void write (int x)
{
if(aux[x]>0)
write (aux[x]);
g<<a[x]<<" ";
}
int main(){
int i,poz,maxm=0,imax;
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
b[1]=1;
for(i=2;i<=n;i++)
{
poz=cautare(a[i]);
aux[i]=b[poz-1];
b[poz]=i;
if(poz>c) c++;
if(poz>maxm) {
maxm=poz;
imax=i;
}
}
g<<maxm<<endl;
write (imax);
f.close();
g.close();
return 0;
}