Skip to main content
deleted 4 characters in body
Source Link
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}}

{21, {1, 7}}

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}}
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}}

added 4 characters in body
Source Link
m0nhawk
  • 3.9k
  • 1
  • 21
  • 35
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}}

{21, {1, 7}}
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}}

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}}
deleted 13 characters in body
Source Link
Henrik Schumacher
  • 109.5k
  • 7
  • 186
  • 323
f = a \[Function] 
   With[{A = 
      UpperTriangularize[
       Outer[PlusUpperTriangularize[Outer[Plus, Join[{0}, -Most[#]], #, 1] &[Accumulate[a]]]},
    MaximalBy[
      Flatten[MapIndexed[{x, i} \[Function] {x, i}, A, {2}], 1], 
      First][[1]]First
      ][[1]]
    ];

{sum, pos} = f[{1, 2, 3, 4, 5, -1, 7, -4, -2}]

{21, {1, 7}}

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}}

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}}

Source Link
Henrik Schumacher
  • 109.5k
  • 7
  • 186
  • 323
Loading