Pagini recente » Cod sursa (job #466577) | Cod sursa (job #1816708) | Cod sursa (job #2839440) | Cod sursa (job #996729) | Cod sursa (job #742104)
Cod sursa(job #742104)
#include <cstdio>
#include <cstdlib>
using namespace std;
#define nmax 500010
int v[nmax], deque[nmax], n, k, max = -nmax, start, end, front, back;
char c;
int main()
{
freopen("secventa.in","r",stdin);
freopen("secventa.out","w",stdout);
int i = 1, j;
bool ok = false;
scanf("%i %i", &n, &k);
scanf("\n");
int number = 0;
while(c != '\n')
{
scanf("%c", &c);
if(c == '\n') break;
if(c == '-') ok = true;
else
{
if(c != ' ')
{
number = number * 10 + (c - '0');
}else
{
if(ok == true) v[i++] = number * (-1);
else v[i++] = number;
ok = false;
number = 0;
}
}
}
v[i++] = number;
front = 1;
back = 1;
deque[1] = 1;
for(i = 2; i < k; ++i)
{
while(front <= back && v[i] <= v[ deque[back] ]) back--;
deque[++back] = i;
}
for(i = k; i<=n; ++i)
{
while(front <= back && v[i] <= v[ deque[back] ]) back--;
deque[++back] = i;
if(v[ deque[front] ] > max)
{
max = v[ deque[front] ];
start = i - k + 1;
end = i;
}
if(deque[front] < i - k + 2) front++;
}
printf("%i %i %i", start, end, max);
return 0;
}