list = {2, 1, 8, 10, 1, 4, 4, 5, 3, 4, 4, 11, 12};
th = 10;
It is easy to create sublists whose totals don't exceed th
:
SequenceCases[list, a : {___} /; Total[a] <= th :> a]
{{2, 1}, {8}, {10}, {1, 4, 4}, {5, 3}, {4, 4}, {}, {}}
But how can we include the exceeding element to get
{{2, 1, 8}, {10, 1}, {4, 4, 5}, {3, 4, 4}, {11}, {12}}
I tried many combinations like for example:
SequenceCases[list, a : {Shortest[__]} /; Total[a] > th :> a]
{{2, 1, 8, 10, 1, 4, 4, 5, 3, 4, 4, 11, 12}}
To see what went wrong with this and other attempts I would like to get a solution, if possible, with one of the Sequence- or Replace-functions.