Pagini recente » Cod sursa (job #3245112) | Cod sursa (job #1886556) | Cod sursa (job #655901) | Cod sursa (job #3200508) | Cod sursa (job #2461218)
#include <iostream>
#include <fstream>
#define nmax 100001
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
int n, best[nmax], poz[nmax], maxim, p, a[nmax];
void read(){
in >> n;
for(int i = 1; i<=n; i++)
in >> a[i];
}
void solve(){
maxim = -1;
best[n] = 1;
poz[n] = -1;
for(int i = n - 1; i>=1; i--){
best[i] = 1;
poz[i] = -1;
for(int j = i + 1; j<=n; j++){
if(a[i] < a[j] && best[i] < best[j] + 1){
best[i] = best[j] + 1;
poz[i] = j;
}
if(maxim < best[i]) maxim = best[i], p = i;
}
}
}
void constr(){
while(p!=-1){
out << a[p] <<' ';
p = poz[p];
}
}
int main(){
read();
solve();
out << best[p] <<"\n";
constr();
return 0;
}