Cod sursa(job #3297475)

Utilizator G3K0Airinei Gabriel Vlad G3K0 Data 22 mai 2025 17:54:12
Problema Schi Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <bits/stdc++.h>


using namespace std;
ifstream f("schi.in");
ofstream g("schi.out");
void nos()
{
    ios_base::sync_with_stdio(false);
    f.tie(NULL);
}


int  main()
{
    nos();
    stack <int> aux;
    deque <int> ordine;
//cout<<ordine.size();
    int n;
    f>>n;
    for(int i=1; i<=n; i++)
    {

        int poz;
        f>>poz;
        if(ordine.size()+1==poz)
            ordine.push_back(i);
        else
        {

            if(ordine.size()>=poz)
            {
                while(ordine.size()>=poz)
                {
                    aux.push(ordine.back());
                    ordine.pop_back();
                }
            }
            else
                while(ordine.size()+1!=poz)
                {
                    ordine.push_back(aux.top());
                    aux.pop();
                }
            ordine.push_back(i);



        }


    }
    while(!aux.empty())
    {
        ordine.push_back(aux.top());
        aux.pop();
    }
    while(!ordine.empty())
    {
        g<<ordine.front()<<'\n';
        ordine.pop_front();

    }

    return 0;
}