Pagini recente » Cod sursa (job #2281933) | Cod sursa (job #1273854) | Cod sursa (job #229486) | Cod sursa (job #372139) | Cod sursa (job #1165345)
#include <fstream>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
const int N = 1e5 + 5;
int best[N], v[N], t[N], last[N], nr = 1, n;
int bs(int x) {
int poz = 0, step = 1;
while (step <= nr)
step <<= 1;
for (; step; step >>= 1)
if (poz + step <= nr && 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] = 1;
for (int i = 2; i <= n; ++i) {
int crt = bs(v[i]);
t[i] = last[crt];
best[i] = crt + 1;
last[crt + 1] = i;
if (nr < crt + 1)
nr = crt + 1;
}
fout << nr << "\n";
write (last[nr]);
}