Pagini recente » Cod sursa (job #1460314) | Cod sursa (job #2974855) | Cod sursa (job #2426522) | Cod sursa (job #3195054) | Cod sursa (job #1459821)
#include<cstdio>
#include <bits/stdc++.h>
#define INF -30001
using namespace std;
int n, k, i, maxx = INF, ind, nr=1, sign;
int v[500001], Deque[500001];
char ch = '0';
int prim, ult;
long long sum;
void citire()
{
ch = '0';
while( (int)ch != 10 )
{
scanf("%c", &ch);
sign = 1;
if ( ch == '-')
sign=-1;
else
v[nr]= ((int)ch) - 48;
scanf("%c", &ch);
while( (int)ch > 32)
{
v[nr]=v[nr]*10 + (int)ch - 48;
scanf("%c", &ch);
}
v[nr] *= sign;
nr++;
}
}
int main()
{
freopen("secventa.in","r",stdin);
freopen("secventa.out","w",stdout);
scanf("%d%d\n", &n, &k);
citire();
/*for(i=1; i<=n; i++)
printf("%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);
}