Pagini recente » Cod sursa (job #90006) | Monitorul de evaluare | Cod sursa (job #1443247) | Cod sursa (job #1187403) | Cod sursa (job #1219345)
#include <iostream>
#include <stdio.h>
using namespace std;
typedef long long ll;
int n,k,a[50005];
int main(){
freopen("secv2.in","r",stdin);
freopen("secv2.out","w",stdout);
scanf("%d%d",&n,&k);
for(int i = 0; i < n; i++){
scanf("%d",&a[i]);
}
ll max = 0,bestSum = 0;
int startPoz = 0,endPoz = 0,finStartPoz = 0;
for(int i = 0; i < k; i++){
bestSum += a[i];
}
for(int i = 1; i < n; i++){
if(max + (ll)a[i] >= (ll)a[i])
max += (ll)a[i];
else
max = (ll)a[i],
startPoz = i;
if(bestSum < max){
if(i - startPoz >= k) {
bestSum = max;
endPoz = i,
finStartPoz = startPoz;
}
}
}
printf("%d %d %lld\n",finStartPoz + 1,endPoz + 1,bestSum);
return 0;
}