Cod sursa(job #3030341)

Utilizator stefandutastefandutahoria stefanduta Data 17 martie 2023 17:02:07
Problema Subsir crescator maximal Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream>
#include <stack>
#include <vector>
#define NMAX 100005

using namespace std;

ifstream in("scmax.in");
ofstream out("scmax.out");

vector <int> v;
vector <int> rez;

int main()
{
    int n, i, j, a, maxx = -1;
    in >> n;
    for (i = 1; i <= n; ++i)
    {
        in >> a;
        while (v.size() > 0 && v[v.size() - 1] >= a)
            v.pop_back();

        v.push_back(a);

        /*for (j = 0; j < v.size(); ++j)
            out << v[j] << " ";
        out << '\n';*/

        int x = v.size();
        if (x > maxx)
        {
            rez = v;
        }
    }

    out << rez.size() << '\n';
    for (i = 0; i < rez.size(); ++i)
        out << rez[i] << " ";
    return 0;
}