#abc261d. D - Flipping and Bonus
D - Flipping and Bonus
Score : points
问题描述
高桥将连续抛掷一枚硬币 次。他还有一个计数器,初始值为 。
根据第 次抛硬币的结果,会发生以下情况:
- 若正面朝上:高桥将计数器的值增加 ,并获得 日元(日本货币)。
- 若反面朝上:他会将计数器的值重置为 ,且不会收到钱。
另外,存在 种连续奖励。第 种连续奖励会在计数器显示为 每次时发放 日元。
请找出高桥最多可以获得的钱款数额。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi will toss a coin times. He also has a counter, which initially shows .
Depending on the result of the -th coin toss, the following happens:
- If it heads: Takahashi increases the counter's value by and receives yen (Japanese currency).
- If it tails: he resets the counter's value to , without receiving money.
Additionally, there are kinds of streak bonuses. The -th kind of streak bonus awards yen each time the counter shows .
Find the maximum amount of money that Takahashi can receive.
Constraints
- are all different.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum amount of money that Takahashi can receive, as an integer.
Sample Input 1
6 3
2 7 1 8 2 8
2 10
3 1
5 5
Sample Output 1
48
If he gets head, head, tail, head, head, head, in this order, the following amounts of money are awarded.
- In the -st coin toss, the coin heads. Change the counter's value from to and receive yen.
- In the -nd coin toss, the coin heads. Change the counter's value from to and receive yen. Additionally, get yen as a streak bonus.
- In the -rd coin toss, the coin tails. Change the counter's value from to .
- In the -th coin toss, the coin heads. Change the counter's value from to and receive yen.
- In the -th coin toss, the coin heads. Change the counter's value from to and receive yen. Additionally, get yen as a streak bonus.
- In the -th coin toss, the coin heads. Change the counter's value from to and receive yen. Additionally, get yen as a streak bonus.
In this case, Takahashi receives yen in total, which is the maximum possible.
Note that streak bonuses are awarded any number of times each time the counter shows .
As a side note, if he gets head in all coin tosses, he only receives yen, which is not the maximum.
Sample Input 2
3 2
1000000000 1000000000 1000000000
1 1000000000
3 1000000000
Sample Output 2
5000000000
Note that the answer may not fit into a -bit integer type.
update @ 2024/3/10 11:03:49