Pagini recente » Cod sursa (job #953336) | Profil fituica | Cod sursa (job #1344385) | Cod sursa (job #1714009) | Cod sursa (job #483325)
Cod sursa(job #483325)
#include <fstream>
#define nmax 100001
#define INF 0x3f3f3f
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
int Q[nmax],V[nmax],S[nmax],P[nmax];
int L,N;
int insert(int key)
{
int st = 1,dr = L,m;
while(st<=dr)
{
m = (st+dr)/2;
if(Q[m]>=key&&Q[m-1]<key)
{
Q[m] = key;
return m;
}
else
if(Q[m]<=key)
st = m+1;
else dr = m+1;
}
L++;
Q[L] = key;
return L;
}
int main()
{
int k,i;
in>>N;
for(i=1;i<=N;i++)
in>>V[i];
L=1;
Q[1] = INF;
for(i=1;i<=N;i++)
P[i] = insert(V[i]);
k = N;
out<<L<<'\n';
for(i=L;i;i--){while(P[k]!=i)k--;out<<V[k]<<' ';}
return 0;
}
/*
http://infoarena.ro/job_detail/256866?action=view-source
http://infoarena.ro/job_detail/256853?action=view-source
http://infoarena.ro/job_detail/215282?action=view-source
*/