Pagini recente » Cod sursa (job #848900) | Cod sursa (job #951005) | Cod sursa (job #567445) | Cod sursa (job #429527) | Cod sursa (job #1349524)
#include <fstream>
#define NMAX 100005
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n, lg, cmax = 2000000009;
int a[NMAX], best[NMAX], sol[NMAX];
int bsrc(int x)
{
int step = 1, rez = 0;
while (step < lg) step <<= 1;
for (; step; step >>= 1)
if (best[rez + step] < x && rez + step <= lg) rez += step;
if (rez == lg) ++lg;
return rez + 1;
}
int main()
{
fin >> n;
for (int i = 1; i <= n; ++i)
{
fin >> a[i];
best[ bsrc(a[i]) ] = a[i];
}
int poz = lg;
for (int i = n; i >= 1; --i)
if (a[i] >= best[poz] && a[i] < cmax)
{
sol[poz--] = a[i];
cmax = a[i];
}
fout << lg << '\n';
for (int i = 1; i <= lg; ++i)
fout << sol[i] << ' ';
fout << '\n';
return 0;
}