# Cod sursa(job #2946910)

Utilizator Data 25 noiembrie 2022 12:21:17 Secventa 0 cpp-64 done Arhiva de probleme 1.24 kb
``````#include <fstream>
#include <deque>
#include <stdio.h>
using namespace std;

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

const int N = 5e5 + 5;

deque<int> Q;
int n, k, bazaMax = -32001, v[N];
int i_final;

// citeste si returneaza urmatorul numar intreg din fisier
void get(int& x);

int main()
{
freopen("secventa.in", "r", stdin);
freopen("secventa.out", "w", stdout);
get(n);
get(k);
for (int i = 1; i <= n; ++i)
{
get(v[i]);
while (!Q.empty() && v[i] < v[Q.back()])
Q.pop_back();

if (!Q.empty() && Q.front() + k == i)   // vom adauga pe i deci vom depasi lungimea k
Q.pop_front();

Q.push_back(i);

if (i >= k && v[Q.front()] > bazaMax)
{
bazaMax = v[Q.front()];
i_final = i;
}
}

int i_initial = i_final - k + 1;

printf("%d %d %d", i_initial, i_final, bazaMax);

return 0;
}

const int Lim = 10000000;
int p =  Lim - 1;
char s[Lim];

void Next()
{
if (++p == Lim)
fread(s, 1, Lim, stdin), p = 0;
}

void get(int &x)
{
for (; s[p] < '0' || s[p] > '9'; Next());
for (x = 0; s[p] >= '0' && s[p] <= '9'; Next())
x = x * 10 + s[p] - '0';
}
``````