#abc250g. G - Stonks
G - Stonks
Score : points
问题描述
你将在接下来的 天内交易公司 X 的股票。
作为一名先知,你知道第 天交易时的股价为每股 日元(日本货币单位)。
每天,你可以选择执行以下操作之一:
- 花费 日元购买一股股票。
- 你将获得一股股票,并且你的资金将减少 日元。
- 以 日元的价格卖出一股股票。
- 你将失去一股股票,并且你的资金将增加 日元。
- 什么都不做。
最初你拥有 日元,因此你永远不会缺钱。
计算当第 天结束时,你能获得的最大金额。 即使在第 天结束时你还持有公司 X 的一定数量的股票,这些股票也被认为价值为 日元。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are going to trade stocks of Company X for the next days.
As a precognitive, you know that the stock price on the -th day of trading will be yen (the currency in Japan) per unit.
Every day, you can choose to do exactly one of the following.
- Buy one unit of stock for yen.
- You will obtain one unit of stock and your money will decrease by yen.
- Sell one unit of stock for yen.
- You will lose one unit of stock and your money will increase by yen.
- Do nothing.
You initially have yen, so you will never be short of money.
Find the maximum possible amount of money you will have gained when the -th day has ended.
Even if you still possess some amount of stocks of Company X when the -th day has ended, it is considered that they are worth yen.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
8
2 5 4 3 7 1 8 6
Sample Output 1
16
By acting as follows, your money will increase by yen, which is the maximum possible.
- On the -th day, you buy unit of stock. You now have unit of stock, and your money has increased by yen so far.
- On the -nd day, you sell unit of stock. You now have units of stocks, and your money has increased by yen so far.
- On the -rd day, you buy unit of stock. You now have unit of stock, and your money has increased by yen so far.
- On the -th day, you buy unit of stock. You now have units of stocks, and your money has increased by yen so far.
- On the -th day, you sell unit of stock. You now have unit of stock, and your money has increased by yen so far.
- On the -th day, you buy unit of stock. You now have units of stocks, and your money has increased by yen so far.
- On the -th day, you sell unit of stock. You now have unit of stock, and your money has increased by yen so far.
- On the -th day, you sell unit of stock. You now have units of stocks, and your money has increased by yen so far.
Sample Input 2
5
10000 1000 100 10 1
Sample Output 2
0
Sample Input 3
15
300 1 4000 1 50000 900000000 20 600000 50000 300 50000 80000000 900000000 7000000 900000000
Sample Output 3
2787595378
update @ 2024/3/10 10:41:56