LCC '22 Contest 6 J5 - AP Videos

View as PDF

Points: 7
Time limit: 4.0s
Memory limit: 256M

Author:
Problem type

It's the day before the AP CS exam, and Chelsea realizes she has yet to finish her AP practice on collegeboard.org!

There are quizzes she must complete, in order, from to , with the -th quiz requiring a knowledge level of . To complete the quizzes, Chelsea can watch one of the AP videos to increase her knowledge level by .

She starts with a knowledge level of , and each video takes her minutes to watch. However, as she doesn't have much time, Chelsea figures she could also google the answer to a quiz in minutes, where is the difference between Chelsea's current knowledge level and the knowledge level required to complete the quiz.

Assuming the time it takes Chelsea to actually write a quiz is negligible, what is the minimum time for Chelsea to finish all the quizzes?

Input Specification

The first line of input will contain integers: , , and .

The next line will contain integers, the -th integer representing the knowledge level required to complete the -th quiz.

Output Specification

Output one integer, the minimum time for Chelsea to finish all the quizzes. Note the answer may not fit in a 32-bit integer.

Sample Input

4 5 3
1 8 10 9

Sample Output

48

Sample Explanation

It can be proven it is most optimal for Chelsea to first watch an AP video to do the first quiz (raising her knowledge level to ), then watch seven more videos to do the second quiz (raising her knowledge level to ), then watch one final video (raising her knowledge level to ) before googling the answer to the third quiz in minutes. Note she does not need to spend any time on the fourth quiz.