Cod sursa(job #2916232)

Utilizator verde.cristian2005Verde Flaviu-Cristian verde.cristian2005 Data 28 iulie 2022 15:56:21
Problema Secventa Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.35 kb
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int dim=1<<17;
char next_ch()
{
    static int bp=dim;
    static char buff[dim];
    if(bp==dim)
    {
        fread(buff,1,dim,stdin);
        bp=0;
    }
    return buff[bp++];
}
void get(int &a)
{
    a=0;
    char ch;
    do
    {
        ch=next_ch();
    }
    while(ch<'0'||'9'<ch);
    do
    {
        a=a*10+ch-'0';
        ch=next_ch();
    }
    while('0'<=ch&&ch<='9');
}
int n,k;
int v[500001];
bool good(int val)
{
    int cnt=0;
    for(int i=1; i<=n; i++)
    {
        if(v[i]>=val)
            cnt++;
        else
            cnt=0;
        if(cnt>=k)
            return 1;
    }
    return 0;
}
int cautbin()
{
    int r=-30000,pas=1<<15;
    while(pas)
    {
        if(good(r+pas))
            r+=pas;
        pas/=2;
    }
    return r;
}
int main()
{
    freopen("secventa.in","r",stdin);
    freopen("secventa.out","w",stdout);
    ios_base::sync_with_stdio(false);
    get(n);
    get(k);
    for(int i=1; i<=n; i++)
        get(v[i]);
    int r=cautbin(),cnt=0;
    for(int i=1; i<=n; i++)
    {
        if(v[i]>=r)
            cnt++;
        else
            cnt=0;
        if(cnt==k)
        {
            cout<<i-cnt+1<<" "<<i<<" "<<r;
            return 0;
        }
    }
    return 0;
}