#include <stdio.h>
int main()
{
int arr[] = {-2, -3, 4, -1, -2, 1, 5, -3};
int best = -1110;
int sum = 0;
int indx = 0;
int i = 0;
int x = 0;
int y = 0;
int n = 8;
for (i = 0; i < n; i++) {
if (sum <= 0) {
sum = arr[i];
indx = i;
} else {
sum += arr[i];
}
if (best < sum) {
best = sum;
x = indx;
y = i;
}
}
printf("Max sum %d, start index %d, end index %d\n", best
, x
, y
);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbigpCnsKICAgIGludCBhcnJbXSA9IHstMiwgLTMsIDQsIC0xLCAtMiwgMSwgNSwgLTN9OwoKICAgIGludCBiZXN0ID0gLTExMTA7CiAgICBpbnQgc3VtID0gMDsKICAgIGludCBpbmR4ID0gMDsKICAgIGludCBpID0gMDsKICAgIGludCB4ID0gMDsKICAgIGludCB5ID0gMDsKICAgIGludCBuID0gODsKCiAgICBmb3IgKGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgaWYgKHN1bSA8PSAwKSB7CiAgICAgICAgICAgIHN1bSA9IGFycltpXTsKICAgICAgICAgICAgaW5keCA9IGk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc3VtICs9IGFycltpXTsKICAgICAgICB9CgogICAgICAgIGlmIChiZXN0IDwgc3VtKSB7CiAgICAgICAgICAgIGJlc3QgPSBzdW07CiAgICAgICAgICAgIHggPSBpbmR4OwogICAgICAgICAgICB5ID0gaTsKICAgICAgICB9CiAgICB9CgogICAgcHJpbnRmKCJNYXggc3VtICVkLCBzdGFydCBpbmRleCAlZCwgZW5kIGluZGV4ICVkXG4iLCBiZXN0LCB4LCB5KTsKCiAgICByZXR1cm4gMDsKfQo=