Pagini recente » Cod sursa (job #1392277) | Cod sursa (job #1530435) | Cod sursa (job #352304) | Cod sursa (job #1488394) | Cod sursa (job #1864419)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
const int maxn = 1e5 + 5;
int Best[maxn], Pre[maxn], V[maxn], maxx;
inline int Bin_search(int val) {
int left = 1, right = maxx, mid;
while (left <= right) {
mid = (left + right) >> 1;
if (V[Best[mid]] < val) {
left = mid + 1;
}
else {
right = mid - 1;
}
}
return left;
}
void Secventa(int x) {
if(Pre[x]) {
Secventa(Pre[x]);
}
fout << V[x] << " ";
}
int main() {
ios_base :: sync_with_stdio (false);
int n, i, pos;
fin >> n;
for (i = 1; i <= n; i++) {
fin >> V[i];
}
for (i = 1; i <= n; i++) {
pos = Bin_search(V[i]);
maxx = max(maxx, pos);
Best[pos] = i;
Pre[i] = Best[pos - 1];
}
fout << maxx << "\n";
Secventa(Best[maxx]);
fin.close();
fout.close();
return 0;
}