Pagini recente » Cod sursa (job #1642202) | Cod sursa (job #888402) | Cod sursa (job #564278) | Cod sursa (job #2204511) | Cod sursa (job #1462797)
#include <stdio.h>
#define nmax 500005
#define SIZE 3500005
int n, k, baza, index;
int a[nmax], deque[nmax], i, j;
int first = 1, last = 0;
char string[SIZE];
char nr[20];
int main()
{
FILE *in, *out;
in = fopen("secventa.in", "r");
out = fopen("secventa.out", "w");
fscanf(in, "%d %d\n", &n, &k);
/*for (i = 1; i <= n; i++)
{
fgets(nr, 20, in);
j = (nr[0] == '-' ? 1 : 0);
while (nr[j] >= '0' && nr[j] <= '9')
a[i] = a[i]*10 + nr[j++] - '0';
a[i] *= (nr[0] == '-' ? -1 : 1);
}*/
for (i = 1; i <= n; i++)
fscanf(in, "%d", &a[i]);
for (i = 1; i <= n; i++)
{
while(first <= last && a[i] <= a[deque[last]])
last--;
deque[++last] = i;
if (i - deque[first] == k)
first++;
if (i >= k)
{
if (baza < a[deque[first]])
{
baza = a[deque[first]];
index = deque[first];
}
}
}
while (a[index-1] >= baza)
index--;
fprintf(out, "%d %d %d\n", index, index + k-1, baza);
}