Pagini recente » Cod sursa (job #2727785) | Cod sursa (job #2603169) | Cod sursa (job #1316587) | micuti1 | Cod sursa (job #550787)
Cod sursa(job #550787)
#include <fstream>
using namespace std;
ofstream g("scmax.out");
int n, v[100003], best[100003], p[100003], maxim, k, L[100003], nr;
void afis(int i)
{
if (p[i] > 0)
afis(p[i]);
g<<v[i]<<" ";
}
int caut(int x)
{
int p, u, m;
p = 0; u = nr; m = (p+u)/2;
while (p <= u)
{
if (v[L[m]] < x && v[L[m+1]] >= x)
return m;
else
if (v[L[m+1]] < x)
{
p = m + 1;
m = (p + u)/2;
}
else
{
u = m - 1;
m = (p + u)/2;
}
}
return nr;
}
int main()
{
ifstream f("scmax.in");
int i, j, poz;
nr = 1;
f>>n;
for (i = 1; i <= n; i++)
f>>v[i];
best[1] = L[1] = 1; L[0] = 0;
for (i = 2; i <= n; i++)
{
poz = caut(v[i]);
p[i] = L[poz];
best[i] = poz + 1;
L[poz + 1] = i;
if (nr < poz + 1)
nr = poz + 1;
}
maxim = 0; poz = 0;
for (i = 1; i <= n; i++)
if (maxim < best[i])
{
maxim = best[i];
poz = i;
}
g<<maxim<<"\n";
afis(poz);
return 0;
}