Cod sursa(job #2718714)

Utilizator pimao2004Lupu Stefan Dragos pimao2004 Data 9 martie 2021 02:08:13
Problema Secventa Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <cstdio>
#include <deque>
/**L9 GANG LEADER
WHEN THE IMPOSTOR IS SUS?????? SOLOBOLO
*/
using namespace std;
deque<int> dq;
int v[500007];
const int dim=(1<<17);
char next_char()
{
    static int bpoint=dim;
    static char buff[dim];
    if(bpoint==dim)
    {
        fread(buff,1,dim,stdin);
        bpoint = 0;
    }
    return buff[bpoint++];
}
void read(int &x)
{
    int sgn=1;
    char ch;
    do
    {
        ch=next_char();
        if(ch=='-')
            sgn=-1;
    }while(ch<'0'||'9'<ch);
    x=0;
    do
    {
        x=x*10+ch-'0';
        ch=next_char();
    }while('0'<=ch&&ch<='9');
    x=x*sgn;
}
int main()
{
    freopen("secventa.in","r",stdin);
    freopen("secventa.out","w",stdout);
    int n,k;
    read(n);
    read(k);
    int x;
    int maxmin=-100000;
    int p1,p2;
    for(int i=1;i<=n;i++)
    {
        read(v[i]);
        while(!dq.empty()&&v[dq.back()]>=v[i])
            dq.pop_back();
        dq.push_back(i);
        if(i-dq.front()==k)
            dq.pop_front();
        if(i>=k)
        {
            if(maxmin<v[dq.front()])
            {
                maxmin=v[dq.front()];
                p2=i;
                p1=i-k+1;
            }
        }
    }
    printf("%d %d %d",p1,p2,maxmin);
    return 0;
}