Cod sursa(job #521484)

Utilizator APOCALYPTODragos APOCALYPTO Data 12 ianuarie 2011 18:15:52
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
using namespace std;
#include<iostream>
#include<fstream>

int a[500005],dek[500005],N,K,front,back,fi;
ofstream fout("secventa.out");
void solve()
{int i;
    int back=0;
    int front=1;
    a[0]=-0x3f3f3f3f;
    int maxi=0;

    for(i=1;i<=N;i++)
    {
        while(back>=front && a[dek[back]]>a[i]) back--;
        back++;
        dek[back]=i;
        if(i-front==K) front++;
        if(i>=K)
         if(a[maxi]<a[dek[front]])
     {
          fi=i;
          maxi=dek[front];


     }
    }
    for(i=0;i<K;i++)
    {
        fout<<a[i+fi+1]<<" ";
    }
    fout<<'\n';

}

void cit()
{
    ifstream fin("secventa.in");
    int i;
    fin>>N>>K;
    for(i=1;i<=N;i++)
    {
        fin>>a[i];
    }

    fin.close();

}

int main()
{

    cit();

    solve();

    fout.close();

    return 0;
}