Pagini recente » Cod sursa (job #1196601) | Cod sursa (job #922028) | Cod sursa (job #2825037) | Cod sursa (job #1267220) | Cod sursa (job #1219341)
#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 = (ll)-(1<<31),bestSum = (ll)-(1<<31);
int startPoz = 0,endPoz = 0,finStartPoz = 0;
/* for(int i = 0; i < k; i++){
max += a[i];
}*/
bestSum = max;
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;
}