Pagini recente » Cod sursa (job #2166646) | Cod sursa (job #283289)
Cod sursa(job #283289)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define FIN "scmax.in"
#define FOUT "scmax.out"
#define MAX_N 100015
int N;
int sir[MAX_N], tata[MAX_N];
vector<int> pos;
void read() {
scanf("%d", &N);
for (int i = 1; i <= N; ++i)
scanf("%d", &sir[i]);
}
bool comp(const int& a, const int& b) {
return sir[a] < sir[b];
}
void print(int p) {
if (tata[p])
print(tata[p]);
printf("%d ", sir[p]);
}
void solve() {
vector<int>::iterator it;
for (int i = 1; i <= N; ++i) {
it = lower_bound(pos.begin(), pos.end(), i, comp);
if (it != pos.begin())
tata[i] = *(it - 1);
if (it != pos.end())
*it = i;
else
pos.push_back(i);
}
printf("%d\n", (int)pos.size());
print(pos.back());
}
int main() {
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
read();
solve();
return 0;
}