Cod sursa(job #3126975)

Utilizator cattyAninisCatrinel catty Data 7 mai 2023 03:29:14
Problema Secventa Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <bits/stdc++.h>
#define L long long
using namespace std;
ifstream in("secventa.in");
ofstream out("secventa.out");
int n,k,i,ps,pd;
short x,y[500002],m=-30002;
set<short> v;
int main()
{
    in>>n>>k;
    for(i=1; i<=n; ++i)
    {
        in>>x;
        y[i]=x;
        if(i<k)
            v.insert(x);
        else if(i==k)
        {
            v.insert(x);
            if((*v.begin())>m)
                m=(*v.begin()),ps=i-k+1,pd=i;
        }
        else
        {
            v.insert(x);
            v.erase(y[i-k]);
            if((*v.begin())>m)
                m=(*v.begin()),ps=i-k+1,pd=i;
        }
    }
    out<<ps<<" "<<pd<<' '<<m;
}