Cod sursa(job #3321683)

Utilizator postolacheepostolache postolachee Data 11 noiembrie 2025 00:14:38
Problema Secventa Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.18 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
#define ll long long
#pragma GCC optimize ("O3")
#define pb push_back
using namespace std;

int v[500009];
signed main(){
    ifstream cin ("secventa.in");
    ofstream cout ("secventa.out");
    int n, k;cin >> n >> k;
    deque <int> dq;
    for(int i=1;i <= n;i++){
        cin >> v[i];
        if(i <= k){
            while(!dq.empty() && v[dq.back()] > v[i])dq.pop_back();
            dq.pb(i);
        }
    }
    ll maxx=-1e8, id=k;
    for(int i=k + 1;i <= n;i++){
        while(dq.front() <= i - k)dq.pop_front();
        while(!dq.empty() && v[dq.back()] > v[i])dq.pop_back();
        dq.pb(i);
        
        if(maxx < v[dq.front()]){
            maxx=v[dq.front()];
            id=i;
        }
    }
    
    cout << id - k + 1 << " " << id << " " << maxx;
    return 0;
}