Monty is a little sport-lover boy in his village. Everyone knows Monty for his love towards sports. In winter, Monty prefers to play badminton. But, he founds that playing badminton is little costlier than other games he plays. So he need to arrange a good amount of money to fulfil his wish. Monty had a jug of exactly 1 litre capacity. He knows that the price of milk varies from day to day in his locality. He decided to start a business with his small jug. He buys a litre of milk, stores it and sells it in any next day if he finds that profitable for him. After selling milk he plays badminton for two days- the day he sells the milk and the next day. After that, he again tries to find a better profit-making opportunity by buying and selling milk. As you are a great programmer, you will be given with the milk prices of n days. You need to calculate the maximum total profit Monty can make from his business.
This is a companion discussion topic for the original entry at https://toph.co/p/business-for-badminton