Pagini recente » Cod sursa (job #1317826) | Cod sursa (job #2359339) | Cod sursa (job #2246782) | Cod sursa (job #2404350) | Cod sursa (job #615258)
Cod sursa(job #615258)
#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);
for (i = 0; i < n; ++i)
{
scanf("%d",&array[i]);
}
begin = 1;
end = 0;
max = -30000;
maxp = 0;
for (i = 0; i < n; ++i)
{
while (array[i] < array[position[end]] && end >= begin) end--;
while (end >= begin && ((i - position[begin]) >= (k-1))) 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;
}