CF865D Buy Low Sell High
Description
You can perfectly predict the price of a certain stock for the next $ N $ days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when you don't own any. At the end of the $ N $ days you would like to again own zero shares, but want to have as much money as possible.
Input Format
N/A
Output Format
N/A
Explanation/Hint
In the first example, buy a share at $ 5 $ , buy another at $ 4 $ , sell one at $ 9 $ and another at $ 12 $ . Then buy at $ 2 $ and sell at $ 10 $ . The total profit is $ -5-4+9+12-2+10=20 $ .