Pagini recente » Cod sursa (job #2535677) | Cod sursa (job #2798835) | Cod sursa (job #896913) | Cod sursa (job #389854) | Cod sursa (job #615271)
Cod sursa(job #615271)
#include <stdio.h>
#include <fstream>
#include <stdlib.h>
#include <string.h>
using namespace std;
#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;
ifstream in(input);
freopen(output,"w",stdout);
in>>n;
in>>k;
//scanf("%d",&n);
//scanf("%d\n",&k);
for (i = 0; i < n; ++i)
{
//scanf("%d",&array[i]);
in>>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;
if ((i - position[begin]) >= k) ++begin;
position[++end] = i;
if(max < array[position[begin]] && i >= (k-1))
{
max = array[position[begin]];
maxp = i;
}
}
maxp++;
printf("%d %d %d\n",maxp - k + 1, maxp, max);
return 0;
}