Problem G
Transit Card

Since you miss your friends back home, you will frequently be going home for a few days. On the one hand, it seems wasteful to pay for keeping the transit card charged during the days you are away. But on the other hand, if you do not keep it charged then you have to start a new date interval when you get back and will be forced to pay the higher price for a few days again.
Given the pricing scheme and the schedule of which days you are going to be away, you decide to write a program to help you determine the cheapest option.
Input
The first line of input contains an integer
The fourth line of input contains two integers
Output
Output the smallest total cost of your transit card for the
Sample Input 1 | Sample Output 1 |
---|---|
3 20 15 10 7 7 30 0 |
405 |
Sample Input 2 | Sample Output 2 |
---|---|
3 20 15 10 7 7 30 2 5 5 15 25 |
345 |