Pagini recente » Cod sursa (job #2874154) | Cod sursa (job #722718) | Cod sursa (job #2738288) | Cod sursa (job #275053) | Cod sursa (job #2867898)
#include <bits/stdc++.h>
using namespace std;
int n, v[100001], best[100001], poz[100001];
int main() {
ifstream cin("scmax.in");
ofstream cout("scmax.out");
cin >> n;
for(int i = 1; i <= n; i++)
cin >> v[i];
best[n] = 1;
poz[n] = -1;
int nmax = 0, ult = 0;
for(int i = n - 1; i >= 1; i--) {
best[i] = 1;
poz[n] = -1;
for(int j = i + 1; j <= n; j++) {
if(v[i] < v[j] && best[i] < best[j] + 1) {
best[i] = best[j] + 1;
poz[i] = j;
if(nmax < best[i])
nmax = best[i], ult = i;
}
}
}
cout << nmax << endl;
while(ult != -1) {
cout << v[ult] << ' ';
ult = poz[ult];
}
return 0;
}