Pagini recente » Cod sursa (job #274573) | Cod sursa (job #2742037) | Cod sursa (job #596896) | Cod sursa (job #521188) | Cod sursa (job #615268)
Cod sursa(job #615268)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define input "secventa.in"
#define output "secventa.out"
int array[500005], position[500005];
int main()
{
int n,k,i,begin,end,max,maxp;
char *it;
freopen(input, "r",stdin);
freopen(output, "w",stdout);
scanf("%d",&n);
scanf("%d\n",&k);
setvbuf(stdin, NULL, _IOFBF, 1655360);
for (i = 0; i < n; ++i)
{
scanf("%d",&array[i]);
}
begin = 1;
end = 0;
max = -30001;
maxp = 0;
for (i = 0; i < n; ++i)
{
while (array[i] <= array[position[end]] && end >= begin) end--;
while (end >= begin && ((i - position[begin]) >= k)) begin++;
position[++end] = i;
if(i >= (k-1) && max < array[position[begin]])
{
max = array[position[begin]];
maxp = i;
}
}
maxp++;
printf("%d %d %d\n",maxp - k + 1, maxp, max);
return 0;
}