Pagini recente » Cod sursa (job #2250000) | Cod sursa (job #1672596) | Cod sursa (job #701277) | Cod sursa (job #397023) | Cod sursa (job #2658270)
#include <bits/stdc++.h>
#define PII pair<int,int>
#define poz second
#define val first
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
int n, sir[100001];
PII lung[100001]; int lmax, urm[100001];
stack <int> sol;
int pozInLung(int val)
{
int poz = 0;
for(int p = lmax; p; p/=2)
while(poz+p <= lmax && val > lung[poz+p].val)
poz += p;
return poz + 1;
}
int main()
{
in >> n;
for(int i = 1; i <= n; i++)
in >> sir[i];
lung[1] = {sir[1], 1};
lmax = 1;
for(int i = 2; i <= n; i++)
{
int poz = pozInLung(sir[i]);
lung[poz] = {sir[i], i};
urm[i] = lung[poz-1].poz;
lmax = max(lmax, poz);
}
int poz = lung[lmax].poz;
while(poz)
{
sol.push(sir[poz]);
poz = urm[poz];
}
out << lmax << '\n';
while(!sol.empty())
{
out << sol.top() << ' ';
sol.pop();
}
return 0;
}