atcoder#ABC227F. [ABC227F] Treasure Hunting
[ABC227F] Treasure Hunting
Score : points
Problem Statement
We have a grid with horizontal rows and vertical columns. Let denote the square at the -th row from the top and -th column from the left. contains an integer .
Takahashi will depart and repeatedly move one square right or down until reaching . It is not allowed to exit the grid.
The cost of this travel is defined as:
the sum of the greatest integers among the integers written on the squares traversed.
Find the minimum possible cost.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
1 3 2
3 4 5
9
There is only one way to travel, where the traversed squares contain the integers , , from largest to smallest, so we print .
2 2 1
3 2
4 3
3
The minimum cost is achieved by traversing , , in this order.
3 5 3
4 7 8 6 4
6 7 3 10 2
3 8 1 10 4
21