Pagini recente » Cod sursa (job #2158562) | Cod sursa (job #113526) | Cod sursa (job #938894) | Cod sursa (job #1912961) | Cod sursa (job #367848)
Cod sursa(job #367848)
#include<cstdio>
#define maxn 100005
int A[maxn] , B[maxn];
int i , j , n , k , start , end ,minim = 100000000 , maxs = -100000000 ,pozmin;
int main()
{
freopen("secv2.in","r",stdin);
freopen("secv2.out","w",stdout);
scanf("%d %d",&n,&k);
for( i = 1 ; i <= n ; ++i )
scanf("%d",&A[i] ) , B[i] = B[i - 1] + A[i];
for( i = 0 ; i <= n - k ; ++i ){
if ( B[i] < minim ) minim = B[i] , pozmin = i;
if ( B[i + k ] - minim > maxs ) {
maxs = B[i + k] - minim;
start = pozmin + 1 , end = i + k ;
}
}
printf("%d %d %d",start,end,maxs);
return 0;
}