You have stock prices for days. Each day you can buy one share, sell one share, or do nothing. You can hold multiple shares. Find the largest your total profit. Naive greedy fails: you can't know future prices. DP (dynamic programming) with states for "shares held" explodes.
With , you need something smarter. This problem looks like greedy, but it's about choosing optimal buy/sell pairs. Slope Trick tracks the best choices dynamically.