Cod sursa(job #2706137)

Utilizator Cristian25Cristian Stanciu Cristian25 Data 13 februarie 2021 23:01:15
Problema Subsir crescator maximal Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.96 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

void scmax(vector<unsigned> a, unsigned n)
{
    vector<unsigned> scmax(n, 1);
    unsigned lmax = 1;
    #define MAX(a, b) (((a) > (b)) ? (a) : (b))
    for(int i = n - 2; i >= 0; --i)
        for(unsigned j = i + 1; j < n; ++j)
            if(a[i] < a[j])
            {
                scmax[i] = MAX(scmax[i], scmax[j] + 1);
                lmax = MAX(lmax, scmax[i]);
            }
    #undef MAX
    ofstream out("scmax.out");
    out << lmax << endl;
    for(unsigned i = 0; i < n; ++i)
        if(scmax[i] == lmax)
        {
            out << a[i] << ' ';
            --lmax;
            if(!lmax)
                break;
        }
    out.close();
}

int main()
{
    unsigned n;
    ifstream in("scmax.in");
    in >> n;
    vector<unsigned> a(n);
    for(unsigned i = 0; i < n;)
        in >> a[i++];
    in.close();
    scmax(a, n);
    return 0;
}