f = a \[Function]
With[{A = UpperTriangularize[Outer[Plus, Join[{0}, -Most[#]], #, 1] &[Accumulate[a]]]},
MaximalBy[
Flatten[MapIndexed[{x, i} \[Function] {x, i}, A, {2}], 1],
First
][[1]]
];
{sum, pos} = f[{1, 2, 3, 4, 5, -1, 7, -4, -2}]
{21, {1, 7}}