Cod sursa(job #3371968)

Utilizator alibardenMiroescu Eduard Alexandru alibarden Data 1 noiembrie 2026 22:22:44
Problema Secventa Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>
#include <deque>
using namespace std;
ifstream in("secventa.in");
ofstream out("secventa.out");
int a[500001];
int main(){

int n, k;
in >> n >> k;
for(int  i = 1; i <= n; i++){
    in >> a[i];
}
int Max = -30001;
deque<int>d;
int ps;
for(int i = 1; i <= n; i++){
    while(!d.empty() && d.front() <= i-k)
        d.pop_front();
    while(!d.empty() && a[d.back()] >= a[i])
        d.pop_back();
    d.push_back(i);
    if(i >= k){
    int cm = Max;
    Max = max(Max,a[d.front()]);
    if(Max != cm)
       ps= i;
    }
}
 out << ps-k+1 << " " << ps << " " << Max;
in.close();
out.close();
    return 0;
}