Skip to main content
2 of 4
deleted 13 characters in body
Henrik Schumacher
  • 109.5k
  • 7
  • 186
  • 323
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}}

Henrik Schumacher
  • 109.5k
  • 7
  • 186
  • 323