Pagini recente » Cod sursa (job #1527414) | Cod sursa (job #1930642) | Cod sursa (job #830535) | Cod sursa (job #2911295) | Cod sursa (job #1503698)
#include <iostream>
#include <fstream>
using namespace std;
const int MAXN = 100001;
int n, a[MAXN], best[MAXN], maxidx, maxval, TT[MAXN], pos[MAXN];
int main() {
#ifdef LOCAL
freopen("input", "r", stdin);
#else
ifstream cin("subsir2.in");
ofstream cout("subsir2.out");
#endif // LOCAL
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
best[i] = 1;
}
for (int i = 2; i <= n; ++i) {
for (int j = 1; j < i; ++j) {
if (a[j] < a[i] && best[i] < best[j] + 1) {
best[i] = best[j] + 1;
TT[i] = j;
}
}
if (maxval < best[i]) {
maxval = best[i];
maxidx = i;
}
}
cout << maxval << '\n';
int i = maxidx, j = maxval
;
while (i != 0) {
pos[j] = i;
--j;
i = TT[i];
}
for (int i = 1; i <= maxval; ++i) {
cout << a[pos[i]] << ' ';
}
return 0;
}