CF865D Buy Low Sell High
题目描述
你可以完美地预测某只股票接下来 $N$ 天的价格,你想利用这一知识盈利,但你每天只想买卖一股,这表明你每天要么什么都不干,要么买入一股,要么卖出一股。起初你没有股票,你也不能在没有股票时卖出股票。你希望在第 $N$ 天结束时不持有股票,并最大化盈利。
输入格式
无
输出格式
无
说明/提示
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 $ .