Pagini recente » Clasamentul arhivei ACM | Cod sursa (job #3202829) | Cod sursa (job #3260145) | Cod sursa (job #1967526) | Cod sursa (job #762890)
Cod sursa(job #762890)
#include <iostream>
#include <fstream>
using namespace std;
#define nmax 100005
ifstream f("scmax.in");
ofstream g("scmax.out");
int n, a[nmax], bst[nmax], t[nmax];
void citeste(){
f >> n;
for(int i=1; i<=n; i++) f >> a[i];
}
void drum(int x){
if (t[x])drum(t[x]);
g << a[x] << " ";
}
void rezolva(){
int Max = 0;
int poz = 0;
for(int i=1; i<=n; i++){
bst[i] = 1;
for(int j=1; j<i; j++){
if (a[i] > a[j] && bst[i] < bst[j]+1){//daca a[i] mai mare ca a[j] si daca pot continua un sir mai lung ca cel din i de pana acum
bst[i] = bst[j]+1;
t[i] = j;
}
}
if (bst[i] > Max) Max = bst[i], poz = i;
}
g << Max << "\n";
drum(poz);
}
int main(){
citeste();
rezolva();
f.close();
g.close();
}