Creating sum of all numbers within a sequence
From the top of my head I would use a greedy approach, always remove the lowest available number so the potential sum of later steps lessens the least this way. But I do not have a proof for this finding the top possible sum, especially not at 0:21 on Monday :-).

With 2,1,5,3,4(0) it would go to 2,5,3,4(2+1+5=8), then to 2,5,4(8+5+3+4=20), and end at 2,4(20+2+5+4=31). So it finds your sum, but this is just one case.