Cod sursa(job #2526829)

Utilizator eugen5092eugen barbulescu eugen5092 Data 19 ianuarie 2020 11:47:52
Problema Secventa Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <bits/stdc++.h>
using namespace std;
ifstream ci("secventa.in");
ofstream cou("secventa.out");
int n,k,a[500005],nmax;
deque<int>q;
void citire()
{
    ci>>n>>k;
    for(int i=1; i<=n; i++)
    {
        ci>>a[i];
    }


}

void rez()
{
    int x,st,dr,i;
    for(i=1; i<=k; i++)
    {
        x=a[i];
        while(!q.empty()&&x<=a[q.back()] )
        {
            q.pop_back();
        }
        q.push_back(i);

    }
    nmax=a[q.front() ];
    st=1;
    dr=k;
    for(i=k+1; i<=n; i++)
    {
        x=a[i];
        while(!q.empty()&&x<=a[q.back()] )
        {
            q.pop_back();
        }
        q.push_back(i);
        if(q.back()-q.front()>=k )
        {
            q.pop_front();

        }
       // cou<<i<<" "<<x<<" "<<q.front()<< " "<<q.back()<<"\n";
        if(nmax<a[q.front()] )
        {
            nmax=a[q.front()];
            dr=i;
            st=i-k+1;
        }

    }
    cou<<st<<" "<<dr<<" "<<nmax;
}

int main()
{
    citire();
    rez();
    return 0;
}