Pagini recente » Istoria paginii utilizator/z1nk3 | Istoria paginii runda/terente.2 | Cod sursa (job #841625) | Rating Carlo Pintea (robert08) | Cod sursa (job #2211075)
#include <iostream>
#include <stack>
#include <fstream>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
const int maxx = 1e6+1;
int v[maxx],n,lg[maxx],lgmax,prev[maxx],i;
stack <int> s;
int main()
{
in>>n;
for(i=1;i<=n;i++)
in>>v[i];
for(i=1;i<=n;i++)
{
int st=1,dr=lgmax;
while(st<=dr)
{
int mij=(dr+st)/2;
if(v[lg[mij]]<v[i])
st=mij+1;
else
dr=mij-1;
}
if(st>lgmax)
lgmax=st;
lg[st]=i;
prev[i]=lg[dr];
}
int poz=lg[lgmax];
while(poz!=0)
{
s.push(v[poz]);
poz=prev[poz];
}
out<<lgmax<<'/n';
while(!s.empty())
{
out<<s.top()<<' ';
s.pop();
}
return 0;
}