Cod sursa(job #2046106)

Utilizator sabinantonSabin Anton sabinanton Data 23 octombrie 2017 14:33:56
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("secventa.in");
ofstream fout("secventa.out");
int n,m,i,j,v[1000001],stiva[1000001],k,b,vf;
int main()
{
    fin>>n>>k;
    b=n-k;
    for(i=1;i<=n;i++)
    {
        fin>>v[i];
    }
    for(i=1;i<=n;i++)
    {
        while(v[i]>stiva[vf]&&vf>0&&b>0)
            {
                vf--;
                b--;
            }
        stiva[++vf]=v[i];
    }
    for(i=1;i<=vf;i++)
    {
        fout<<stiva[i]<<" ";
    }
    return 0;
}