Pagini recente » Cod sursa (job #3327381) | Cod sursa (job #3322450) | Cod sursa (job #3351942) | Cod sursa (job #2677618) | Cod sursa (job #3322452)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("subsir2.in");
ofstream fout("subsir2.out");
const int m = 9901;
int n, best[10002],v[10002],tata[10002];
void afis(int p){
if(p){
afis(tata[p]);
fout << v[p] << " ";
}
}
int main(){
int i, j, mx, maxi=0,p;
fin >> n;
for(i=1;i<=n;i++){
fin >> v[i];
mx=0;
for(j=1;j<i;j++)
if(v[j] < v[i]){
if(mx == best[j]){
if(v[j] < v[tata[i]])
tata[i] = j;
}
if(mx < best[j]){
mx = best[j];
tata[i] = j;
}
}
best[i] = mx + 1;
if(best[i] == maxi){
if(v[i] < v[p])
p=1;
}
if(best[i] > maxi){
maxi = best[i];
p = i;
}
}
fout << maxi << '\n';
afis(p);
}