For each element of the prefix_sum array do : compute the cand array . take k maximum values from maxi and cand using maxmerge function . insert prefix_sum [ i ] to mini array if needed using insertMini function .
for i in range ( n ) : NEW_LINE INDENT for j in range ( k ) : NEW_LINE INDENT cand [ j ] = pre_sum [ i ] - mini [ j ] NEW_LINE DEDENT maxMerge ( maxi , cand ) NEW_LINE insertMini ( mini , pre_sum [ i ] ) NEW_LINE DEDENT