Pagini recente » Cod sursa (job #417500) | Cod sursa (job #455997) | Cod sursa (job #1088969)
#include <stdio.h>
#define MAXN 500005
int N, K;
int deq[MAXN], front = 1, back = 0;
int sir[MAXN];
int main()
{
freopen("secventa.in", "r", stdin);
freopen("secventa.out", "w", stdout);
int i, inceput, sfarsit, maxim = -30005;
scanf("%d %d", &N, &K);
for (i = 1; i <= N; ++i)
{
scanf("%d", &sir[i]);
while (front <= back && sir[deq[back]] > sir[i])
back--;
deq[++back] = i;
if (deq[front] == i - K)
front++;
if (i >= K && sir[deq[front]] > maxim)
maxim = sir[deq[front]], inceput = i - K + 1, sfarsit = i;
}
printf("%d %d %d\n", inceput, sfarsit, maxim);
return 0;
}