Cod sursa(job #3323591)

Utilizator Minea_TheodorMinea Theodor Stefan Minea_Theodor Data 18 noiembrie 2025 19:23:39
Problema Subsir 2 Scor 55
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("subsir2.in");
ofstream fout("subsir2.out");
const long long INF = 4e18;
const int SIZ=5005;
int v[SIZ];
int main()
{
    int n;
    fin >> n;
    for(int i=1; i <= n; i++)
        fin >> v[i];
    vector<int> rez;
    long long ultval = -INF;
    int ultpos=0;
    while(true)
    {
        int i=ultpos + 1;
        while(i <= n && v[i] < ultval)
            i++;
        if (i > n) break;
        bool ob = true;
        for (int j = i+1; j <= n; j++)
        {
            if(v[j] >= ultval && v[j] < v[i])
            {
                ob= false;
                break;
            }
        }

        if (ob)
        {
            rez.push_back(i);
            ultval = v[i];
            ultpos = i;
        }
        else
            ultpos = i;
    }
    fout << rez.size() << '\n';
    for(auto I : rez)
        fout << I << " ";
    return 0;
}