Pagini recente » Cod sursa (job #7167) | Cod sursa (job #2591014) | Cod sursa (job #2683231) | Cod sursa (job #3149838) | Cod sursa (job #1459827)
#include<cstdio>
#define INF -30001
using namespace std;
int n, k, i, maxx = INF, ind, nr, sign;
int v[500001], Deque[500001];
int prim, ult;
long long sum;
char s[4000003];
int poz=0;
void citire(int i)
{
int semn;
if( s[nr] == '-' )
{
semn = -1;
++nr;
}
else
semn = 1;
while( 48 <= s[nr] && s[nr] <= 57 )
{
v[i] = v[i] * 10 + s[nr] - 48;
++nr;
}
++nr;
v[i] *= semn;
}
int main()
{
freopen("secventa.in","r",stdin);
freopen("secventa.out","w",stdout);
scanf("%d%d\n", &n, &k);
gets(s);
for (i = 1; i <=n; i++)
citire(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);
}