Pagini recente » Cod sursa (job #2974830) | Cod sursa (job #3206716) | Cod sursa (job #2459821) | Cod sursa (job #2128498) | Cod sursa (job #1459780)
#include<cstdio>
#define INF -30001
using namespace std;
int n, k, i, maxx = INF, ind;
int v[500001], Deque[500001];
int prim, ult;
long long sum;
int main()
{
freopen("secventa.in","r",stdin);
freopen("secventa.out","w",stdout);
scanf("%d%d", &n, &k);
for (i = 1; i <= n; i++)
scanf("%d", &v[i]);
prim=1;
ult=0;
for(i = 1; i <= n; i++)
{
while (prim <= ult && v[i] <= v[ Deque[ult] ])
ult--;
Deque[++ult]=i;
if (Deque[prim] == i - k)
prim++;
if (i >= k)
if (v[Deque[prim]] > maxx)
{
ind=i;
maxx=v[Deque[prim]];
}
}
printf("%d %d %d\n", ind - k + 1, ind, maxx);
}