Pagini recente » Cod sursa (job #2560598) | Cod sursa (job #2651982) | Cod sursa (job #544283) | Cod sursa (job #2683204) | Cod sursa (job #809228)
Cod sursa(job #809228)
#include <cstdio>
#include <set>
#include <map>
using namespace std;
int P[1000000];
inline int next_int() {
int d;
scanf("%d", &d);
return d;
}
void dfs(int x) {
if (P[x] >= 0) {
dfs(P[x]);
}
printf("%d ", x);
}
int main() {
freopen("scmax.in", "r", stdin);
freopen("scmax.out", "w", stdout);
multiset<int> S;
multiset<int>::iterator it;
int n = next_int();
while (n--) {
int x = next_int();
S.insert(x);
it = S.lower_bound(x);
if (it == S.begin())
P[x] = -1;
else {
--it;
P[x] = *it;
++it;
}
if (++it != S.end())
S.erase(it);
}
printf("%d\n", int(S.size()));
int x = *S.rbegin();
dfs(x);
return 0;
}