Pagini recente » Cod sursa (job #1831188) | Cod sursa (job #36854) | Cod sursa (job #2645967) | Cod sursa (job #288158) | Cod sursa (job #2547439)
#include <fstream>
using namespace std;
ifstream fi("scmax.in");
ofstream fo("scmax.out");
const int nmax=1e5;
int n, rmost, nrs, lgmax;
int X[nmax+5], last[nmax+5], pre[nmax+5];
int bSearch(int x)
{
int lo=0, hi=nrs, mid, res=0;
while(lo<=hi)
{
mid=lo+(hi-lo)/2;
if(X[last[mid]]<x)
{
res=mid;
lo=mid+1;
}
else
hi=mid-1;
}
return res;
}
void afisare(int pos)
{
if(pre[pos])
afisare(pre[pos]);
fo<<X[pos]<<" ";
}
int main()
{
fi>>n;
for(int i=1; i<=n; i++)
fi>>X[i];
for(int i=1; i<=n; i++)
{
rmost=bSearch(X[i]);
if(rmost==nrs)
{
nrs++;
lgmax++;
}
last[rmost+1]=i;
pre[i]=last[rmost];
}
fo<<lgmax<<"\n";
afisare(last[nrs]);
fi.close();
fo.close();
return 0;
}