This problem can be solved by using a priority queue.

My solution :

Idea is keep a pointer from each element to the last element , and decrement the pointer to the previous element if the subbarray sum is popped out.

To do this we can use a priority queue , pop out and print the largest sum and then modify the pointer and push it back to the queue.


the solutions are not made public yet…