A beginner investor wants to learn how to trade shares. With no experience to go on, he picked a single company and wrote down that company's closing share price on each of N consecutive days. Once he had the record, he wondered how much he could have made by trading over that period. He is wealthy enough to buy any number of shares, but he is careful, so he decided never to hold more than one share at any moment.
A broker always sits in the middle, so the brokerage charges a fixed fee of C for every share he buys.
On each day he does exactly one of three things: buy one share, sell the share he is holding, or nothing. A share he buys must be sold on a later day. The profit of a single trade is the selling price minus the buying price minus the fee C. Compute the largest total profit he could have made by trading on some of the N days. Trading on no day at all is allowed and gives a profit of 0.