Coin Toss Earnings
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Coin Toss Earnings
Problem Statement
Bessie is planning to toss a coin times. She also has a counter, which starts at . The outcome of each toss will impact the counter and Bessie's earnings in the following ways:
- If the coin lands on heads: Bessie increases the counter by 1 and receives dollars.
- If the coin lands on tails: she resets the counter to and doesn't receive any money.
Additionally, there are types of streak bonuses. For each type , Bessie earns a bonus of dollars each time the counter shows .
Bessie is interested in finding out the maximum amount of money she can potentially earn from this coin-tossing game.
INPUT FORMAT (input arrives from the terminal / stdin):
The input is provided in the following format:
- The first line contains two integers and .
- The second line contains integers, for , separated by spaces.
- The next lines each contain two integers and .
OUTPUT FORMAT (print output to the terminal / stdout):
Print a single integer: the maximum amount of money that Bessie can earn from the coin-tossing game.
SAMPLE INPUT 1:
6 3
2 7 1 8 2 8
2 10
3 1
5 5
SAMPLE OUTPUT 1:
48
If Bessie gets heads, heads, tails, heads, heads, heads, in this order, the following amounts of money are awarded:
- In the 1st coin toss, the coin lands on heads. The counter's value changes from to and Bessie receives dollars.
- In the 2nd coin toss, the coin lands on heads. The counter's value changes from to and Bessie receives dollars. Additionally, she gets 10 dollars as a streak bonus.
- In the 3rd coin toss, the coin lands on tails. The counter's value changes from to .
- In the 4th coin toss, the coin lands on heads. The counter's value changes from to and Bessie receives dollars.
- In the 5th coin toss, the coin lands on heads. The counter's value changes from to and Bessie receives dollars. Additionally, she gets dollars as a streak bonus.
- In the 6th coin toss, the coin lands on heads. The counter's value changes from to and Bessie receives dollars. Additionally, she gets dollar as a streak bonus.
In this case, Bessie earns dollars 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 Bessie gets heads in all coin tosses, she only receives dollars, which is not the maximum.
SCORING:
- For all inputs: No additional constraints.
HFI Coding Club 2023 November Contest
- Status
- Done
- Rule
- IOI
- Problem
- 4
- Start at
- 2023-11-16 18:45
- End at
- 2023-11-16 20:45
- Duration
- 2 hour(s)
- Host
- Partic.
- 21