Cod sursa(job #3251330)

Utilizator EricRaiaEricRaia EricRaia Data 25 octombrie 2024 18:52:02
Problema Secventa Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>
#include <deque>

using namespace std;

ifstream cin ("secventa.in");
ofstream cout ("secventa.out");

deque<int> bl;
int v[500001],inc,mini;

int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>v[i];
    for(int i=1;i<=k;i++){
        while(!bl.empty() && v[i]<=v[bl.back()])
            bl.pop_back();
        bl.push_back(i);
    }
    mini=v[bl.front()];
    inc=k;
    for(int i=k+1;i<=n;i++){
        while(!bl.empty() && v[i]<=v[bl.back()])
            bl.pop_back();
        if(!bl.empty() && i-bl.front()>=k)
            bl.pop_front();
        bl.push_back(i);
        if(v[bl.front()]>mini){
            mini=v[bl.front()];
            inc=i;
        }
    }
    cout<<inc-k+1<< ' ' <<inc<< ' ' <<mini;

    return 0;
}