Buy and sell stocks, at most one held at a time, unlimited transactions. get the highest profit. Insight: treat each price as an opportunity. Either buy (add to heap), sell (pop min and profit), or hold. Greedy: when seeing price , compare to heap min .
If , sell (profit ) and add back (can 'regret' and re-buy). Adding back allows changing past decisions. This is the 'regret' trick. Total profit is sum of all positive trades.