Sightseeing in Kyoto
면접 대비시간 제한2초메모리 제한1024 MB
가로 도로 비용 A_i, 세로 도로 비용 B_j인 H×W 격자에서 (1,1)에서 (H,W)까지 남쪽과 동쪽으로만 이동할 때 최소 시간을 구한다.
문제
Kyoto City is a worldwide sightseeing place. It is also known as a city with grid of streets. You are now visiting Kyoto City for sightseeing. You are planning to visit a famous spot on foot. You want to arrive there as early as possible. In this task, we consider the following simplified situation.
In this city, there are streets in the east-west direction, and streets in the south-north direction. The shape of the city is a grid of cells. The crossing of the -th street () from the north and the -th street () from the west is denoted by .
Different streets may have different width, material, and crowdedness. Your walking speed may be different for different streets. For each street, your walking speed is determined as follows.
- If you walk on the -th street () from the north for the unit length, it takes seconds. In other words, for each (), it takes seconds to walk from the crossing to the crossing .
- If you walk on the -th street () from the west for the unit length, it takes seconds. In other words, for each (), it takes seconds to walk from the crossing to the crossing .
In order not to destroy the beautiful landscape of Kyoto City, you are not allowed to walk outside the streets.
Now you are in the crossing . You want to walk to the crossing . Since you will be tired if you walk for long distance, you do not want to make a detour. You will not walk to the north or west direction. Under this condition, you want to arrive at the destination as early as possible.
Write a program which, given information of the streets, calculates the minimum time to walk from the crossing to the crossing without making a detour
입력
Read the following data from the standard input. Given values are all integers.
\begin{align\*} & H \\, W \\\ & A\_1 \\, A\_2 \\, \cdots \\, A\_H \\\ & B\_1 \\, B\_2 \\, \cdots \\, B\_W \end{align\*}
출력
Write one line to the standard output. The output should contain the minimum time (seconds) to walk from the crossing to the crossing without making a detour.
제한
- .
- .
- () ().
- () ().