Help needed in further understanding slope trick

Merchant Otter (
This is a similar question to the Buy Low Sell High covered in the USACO Guide. In Fact it’s basically the extension problem. I have been staring at that question but still couldn’t have a clue or hint on how to approach that question. Do appreciate if anyone could help me out thanks

You can buy 1 stock/sell 1 stock/do nothing each day. Buy price and Selling price is given (not necessary equal). Find max profit. At any given time u can have -L to L stocks (Can sell first before even buy)