Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Monitorul de evaluare | Clasament dupa rating | Cod sursa (job #750876)
Cod sursa(job #750876)
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
const int DIM = 100001;
int N;
int V[DIM], U[DIM], max[DIM], back[DIM], L;
void sscm()
{
U[ L = 0 ] = 0;
int pow = 1, i, now, step;
for(i = 1; i <= N; i++)
{
while((pow << 1) <= L) pow <<= 1;
now = 0;
for(step = pow; step; step >>= 1)
{
if((now + step <= L) && V[U[now+step]]<V[i])
now+=step;
}
max[i] = max[U[now]] + 1;
back[i] = U[now];
if(now == L)
U[++L] = i;
else
if(V[U[now+1]] > V[i])
U[now+1] = i;
}
}
void write(int i)
{
if(i!=0)
{
write(back[i]);
out<<V[i]<<" ";
}
}
int main()
{
int i;
in>>N;
for(i = 1; i<= N; ++i)
in>>V[i];
sscm();
out<<L<<"\n";
for(i=1; i<=N; i++)
if(max[i] == L)
{
write(i);
return 0;
}
return 0;
}