Cod sursa(job #3322450)

Utilizator LucaMirsolea14Luca Mirsolea LucaMirsolea14 Data 14 noiembrie 2025 10:10:54
Problema Subsir 2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 kb
#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);


}