Cod sursa(job #3352780)

Utilizator livliviLivia Magureanu livlivi Data 1 mai 2026 13:47:33
Problema Secventa Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>

using namespace std;

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

int v[500005];
deque <int> q;

int main()
{
	int n, k;
    fin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
    	fin >> v[i];
    }

    int pmax = 0;
    int lmax = 1;
    int rmax = k;
    for (int i = 1; i <= n; i++)
    {
        if (!q.empty() && q.front() <= i - k) { q.pop_front(); }
        while (!q.empty() && v[q.back()] >= v[i]) { q.pop_back(); }
        q.push_back(i);
        if  (i >= k) 
        	if (pmax == 0 || v[q.front()] > v[pmax])
            {
                lmax = i - k + 1;
                rmax = i;
                pmax = q.front();
            }
    }
    fout << lmax << " " << rmax << " " << v[pmax];
    return 0;
}