Traverse the mini array from left to right . If prefix_sum [ i ] is less than any element then insert prefix_sum [ i ] at that position and delete maximum element of the mini array i . e . the rightmost element from the array .
k = len ( mini ) NEW_LINE for i in range ( k ) : NEW_LINE INDENT if ( pre_sum < mini [ i ] ) : NEW_LINE INDENT mini . insert ( i , pre_sum ) NEW_LINE del mini [ - 1 ] NEW_LINE break NEW_LINE DEDENT DEDENT