Cod sursa(job #2672600)

Utilizator CotoiRaresCotoi Rares CotoiRares Data 14 noiembrie 2020 11:38:00
Problema Subsir crescator maximal Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("scmax.in");
ofstream out("scmax.out");
int v[100000];
deque <int> q;

void solve(int& n, int poz)
{
    int i, aux,max=0;
    for (i = poz + 1; i < n; i++)
    {
        if (v[i] > q.front())
            q.push_front(v[i]);
        else if (v[i] < q.front())
        {
            if (q.size()>max)
            max=q.size();
            while (v[i]<q.front() && !q.empty())
            q.pop_front();
            q.push_front(v[i]);
        }
    }
    out << q.size() << '\n';
    while (!q.empty())
    {
        out<< q.back() << " ";
        q.pop_back();
    }
}

int main()
{
    int i, n, min, poz;
    in >> n;
    for (i = 0; i < n; i++)
    {
        in >> v[i];
        if (v[i] < min)
        {
            min = v[i];
            poz = i;
        }
    }
    poz=0;
    q.push_back(v[0]);
    solve(n, poz);

}