Pagini recente » Cod sursa (job #2083705) | Cod sursa (job #1532130) | Cod sursa (job #2284046) | Cod sursa (job #2495474) | Cod sursa (job #1969973)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
const int maxn = 1e5 + 5;
int V[maxn], Best[maxn], Pre[maxn];
int n, maxx;
int Bin_search(int val) {
int pos = 1;
int l = 1;
int r = maxx;
while (l <= r) {
int mid = (l + r) >> 1;
if (V[Best[mid]] < val) {
l = mid + 1;
pos = l;
} else {
r = mid - 1;
}
}
return pos;
}
void Sequence(int x) {
if (Pre[x]) Sequence(Pre[x]);
fout << V[x] << " ";
}
int main() {
ios_base :: sync_with_stdio(false);
fin >> n;
for (int i = 1; i <= n; i++) {
fin >> V[i];
}
for (int i = 1; i <= n; i++) {
int pos = Bin_search(V[i]);
maxx = max(maxx, pos);
Best[pos] = i;
Pre[i] = Best[pos - 1];
}
fout << maxx << "\n";
Sequence(Best[maxx]);
return 0;
}