Cod sursa(job #71520)
#include <cstdio>
#define maxn 500001
FILE *in = fopen("secventa.in","r"), *out = fopen("secventa.out","w");
int n;
int k;
int a[maxn] = {0};
void read()
{
fscanf(in, "%d %d", &n, &k);
for ( int i = 1; i <= n; ++i )
fscanf(in, "%d", &a[i]);
}
struct deque
{
int poz, v;
};
deque Q[maxn];
int main()
{
read();
int first = 1, last = 0;
Q[first].v = a[1];
Q[first].poz = 1;
int max = -300000000;
//int min = 300000000;
int pmin = 0;
for ( int i = 2; i <= n; ++i )
{
while ( first <= last && Q[first].poz <= i - k )
++first;
while ( last >= first && Q[last].v >= a[i] )
--last;
// printf("%d \n", Q[first].v );
++last;
Q[last].v = a[i];
Q[last].poz = i;
if ( Q[first].v > max && Q[first].poz >= k )
max = Q[first].v, pmin = Q[first].poz;
// for ( int j = first; j <= last; ++j )
// printf("%d ", Q[j].v);
// printf("\n");
}
// printf("%d %d\n\n", first, last);
int st = pmin;
int dr = pmin;
while ( a[st] >= max )
--st;
++st;
while ( a[dr] >= max && dr - st < k )
++dr;
--dr;
fprintf(out, "%d %d %d\n", st, dr, max);
return 0;
}