Pagini recente » Cod sursa (job #1951926) | Cod sursa (job #2262166) | Cod sursa (job #2025625) | Cod sursa (job #2466368) | Cod sursa (job #1667141)
#include <fstream>
using namespace std;
ifstream fi("scmax.in");
ofstream fo("scmax.out");
#define N 100001
int u[N], pred[N], v[N];
int m;
int cautbin(int x)
{
int i = 0, pas = 1 << 16;
while (pas != 0)
{
if (i + pas <= m && v[u[i + pas]] < x)
i += pas;
pas /= 2;
}
return i;
}
void sir(int p)
{
if (pred[p] != 0)
sir(pred[p]);
fo << v[p] << " ";
}
int main()
{
int i = 0, j, n, pmax = 0;
m = 0;
fi >> n;
pred[1] = 0;
u[++m] = 1;
for (i = 1; i <= n; i++)
fi >> v[i];
for (i = 2; i <= n; i++)
{
j = cautbin(v[i]);
if (j == m) ++m;
u[j + 1] = i;
if (j + 1 > pmax)
pmax = j + 1;
pred[i] = u[j];
}
fo << pmax << '\n';
sir(u[pmax]);
return 0;
}