Pagini recente » Cod sursa (job #2205576) | Cod sursa (job #1562914) | Cod sursa (job #2816641) | Cod sursa (job #389929) | Cod sursa (job #1377072)
#include <fstream>
#define DIM 100001
using namespace std;
int lung, x[DIM], before[DIM], temp[DIM], n, p;
ifstream in ("scmax.in");
ofstream out("scmax.out");
void afisare(int ind)
{
if(before[ind]!=0)
afisare(before[ind]);
out<<x[ind]<<" ";
}
int find_pos(int ind)
{
int l=1, r=lung, mij;
while(l<=r)
{
mij=(l+r+1)/2;
if(x[temp[mij]]<x[ind])
{
l=mij+1;
}
else
{
r=mij-1;
}
}
return l;
}
int main()
{
in>>n;
for(int i=1; i<=n; ++i) in>>x[i];
temp[1]=1;
lung=1;
for(int i=2; i<=n; ++i)
{
p=find_pos(i);
temp[p]=i;
before[i]=temp[p-1];
if(p>lung)
lung=p;
}
out<<lung<<"\n";
afisare(temp[lung]);
in.close();
out.close();
return 0;
}