아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Sightseeing in Kyoto

면접 대비

시간 제한2초메모리 제한1024 MB

요약
가로 도로 비용 A_i, 세로 도로 비용 B_j인 H×W 격자에서 (1,1)에서 (H,W)까지 남쪽과 동쪽으로만 이동할 때 최소 시간을 구한다.
난이도

보통10점 중 4점

유형
동적 계획법, 행렬, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

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 HH streets in the east-west direction, and WW streets in the south-north direction. The shape of the city is a grid of (H−1)×(W−1)(H - 1) \times (W - 1) cells. The crossing of the ii-th street (1≤i≤H1 ≤ i ≤ H) from the north and the jj-th street (1≤j≤W1 ≤ j ≤ W) from the west is denoted by (i,j)(i, j).

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 ii-th street (1≤i≤H1 ≤ i ≤ H) from the north for the unit length, it takes A_iA\_i seconds. In other words, for each cc (1≤c≤W−11 ≤ c ≤ W - 1), it takes A_iA\_i seconds to walk from the crossing (i,c)(i, c) to the crossing (i,c+1)(i, c + 1).
  • If you walk on the jj-th street (1≤j≤W1 ≤ j ≤ W) from the west for the unit length, it takes B_jB\_j seconds. In other words, for each rr (1≤r≤H−11 ≤ r ≤ H - 1), it takes B_jB\_j seconds to walk from the crossing (r,j)(r, j) to the crossing (r+1,j)(r + 1, j).

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 (1,1)(1, 1). You want to walk to the crossing (H,W)(H, W). 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 (1,1)(1, 1) to the crossing (H,W)(H, W) 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 (1,1)(1, 1) to the crossing (H,W)(H, W) without making a detour.

제한

  • 2≤H≤100,0002 ≤ H ≤ 100\\,000.
  • 2≤W≤100,0002 ≤ W ≤ 100\\,000.
  • 1≤A_i≤1,000,000,0001 ≤ A\_i ≤ 1\\,000\\,000\\,000 (=109= 10^9) (1≤i≤H1 ≤ i ≤ H).
  • 1≤B_j≤1,000,000,0001 ≤ B\_j ≤ 1\\,000\\,000\\,000 (=109= 10^9) (1≤j≤W1 ≤ j ≤ W).

예제3

  1. 예제 1

    입력
    2 2
    1 3
    2 5
    
    예상 출력
    5
    
  2. 예제 2

    입력
    5 5
    7 1 5 2 8
    7 2 4 1 6
    
    예상 출력
    20
    
  3. 예제 3

    입력
    4 6
    454863204 543362989 866044086 813602010
    71574269 17945210 688720933 392135202 38174709 168241720
    
    예상 출력
    2737473954