100 atcoder#ABC094B. [ABC094B] Toll Gates
[ABC094B] Toll Gates
Score : points
Problem Statement
There are squares arranged in a row, numbered from left to right.
Initially, you are in Square . You can freely travel between adjacent squares. Your goal is to reach Square or Square . However, for each , there is a toll gate in Square , and traveling to Square incurs a cost of . It is guaranteed that there is no toll gate in Square , Square and Square .
Find the minimum cost incurred before reaching the goal.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum cost incurred before reaching the goal.
5 3 3
1 2 4
1
The optimal solution is as follows:
- First, travel from Square to Square . Here, there is a toll gate in Square , so the cost of is incurred.
- Then, travel from Square to Square . This time, no cost is incurred.
- Now, we are in Square and we have reached the goal.
In this case, the total cost incurred is .
7 3 2
4 5 6
0
We may be able to reach the goal at no cost.
10 7 5
1 2 3 4 6 8 9
3