Pagini recente » Cod sursa (job #2108688) | Cod sursa (job #1572895) | Cod sursa (job #2968344) | Cod sursa (job #2983780) | Cod sursa (job #2153408)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int N, k, MAX, poz, a[100003], p[100003], st[100003];
int cautbin(int x);
void reconst(int poz, int max);
int main() {
f >> N;
for (int i = 1; i <= N; ++i) {
f >> a[i];
int pozt = cautbin(a[i]);
st[(k = pozt)] = a[i];
p[i] = k;
if(MAX < p[i]) MAX = p[i], poz = i;
}
g << MAX << "\n";
reconst(poz, MAX);
g << "\n";
return 0;
}
void reconst(int poz, int max) {
if(poz < 1) return;
if(p[poz] == max) {
reconst(poz - 1, max - 1);
g << a[poz] << " ";
}
else
reconst(poz - 1, max);
}
int cautbin(int x) {
int s = 1, d = k;
while(s <= d) {
int mij = (s + d) / 2;
if(st[mij] == x)
break;
else if (st[mij] < x)
s = mij + 1;
else
d = mij - 1;
}
return s;
}