https://atcoder.jp/contests/abc261/tasks/abc261_d
D - Flipping and Bonus
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 400400 points
Problem Statement
Takahashi will toss a coin NN times. He also has a counter, which initially shows 00.
Depending on the result of the ii-th coin toss, the following happens:
- If it heads: Takahashi increases the counter's value by 1 and receives Xi yen (Japanese currency).
- If it tails: he resets the counter's value to 0, without receiving money.
Additionally, there are MM kinds of streak bonuses. The i-th kind of streak bonus awards Yi yen each time the counter shows Ci.
Find the maximum amount of money that Takahashi can receive.
Constraints
- 1≤M≤N≤5000<