Pagini recente » Cod sursa (job #2984280) | Cod sursa (job #1351358) | Cod sursa (job #52169) | Cod sursa (job #2838409) | Cod sursa (job #1378382)
#include <fstream>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
const int N = 1e5 + 5;
int v[N], last[N], t[N], best[N], n, sol;
int bs(int x) {
int poz = 0, step = 1;
while ((step << 1) <= n)
step <<= 1;
for (; step; step >>= 1)
if (poz + step <= sol && v[last[poz + step]] < x)
poz += step;
return poz;
}
void write(int x) {
if (t[x])
write(t[x]);
fout << v[x] << " ";
}
int main() {
fin >> n;
for (int i = 1; i <= n; ++i)
fin >> v[i];
best[1] = last[1] = sol = 1;
for (int i = 2; i <= n; ++i) {
int poz = bs(v[i]);
t[i] = last[poz];
best[i] = best[last[poz]] + 1;
last[poz + 1] = i;
if (poz + 1 > sol)
sol = poz + 1;
}
fout << sol << "\n";
write(last[sol]);
}