Cod sursa(job #3363171)

Utilizator CorvinJudge0Corvin Judge CorvinJudge0 Data 14 august 2026 12:11:47
Problema Secventa Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("secventa.in");
ofstream fout ("secventa.out");

int n,k,i,mare,pozl,pozr;
int main()
{
    fin >> n >> k;
    vector<int> v(n+1),st(n+1),dr(n+1);
    stack<int> s1,s2;
    for(i=1;i<=n;i++)
        fin >> v[i] ;
    for(i=1;i<=n;i++)
        {
            while(!s1.empty() && v[i]<=v[s1.top()])
                s1.pop();
            if(s1.empty())
                st[i]=-1;
            else
                st[i]=s1.top();
            s1.push(i);


            int j=n-i+1;
            while(!s2.empty() && v[j]<=v[s2.top()])
                s2.pop();
            if(s2.empty())
                dr[j]=-1;
            else
                dr[j]=s2.top();
            s2.push(j);
        }
    for(i=1;i<=n;i++)
        {
            int l,r;
            l=st[i]+1;
            if(dr[i]==-1)
                r=n;
            else
                r=dr[i]-1;
            if(r-l+1>=k && v[i]>mare)
                {
                    pozl=l ,mare=v[i];
                    pozr=r;
                }
            //cout << i << " " << poz << endl ;
            //cout << i << " " << l << " " << r << " " << v[i] << " " << mare << '\n' ;

        }
    //cout << poz ;
    fout << pozl << " " << pozr << " " << mare;
    return 0;
}