#P9521. [JOIST 2022] 京都观光 / Sightseeing in Kyoto
[JOIST 2022] 京都观光 / Sightseeing in Kyoto
Background
JOISC2022 D1T2
Problem Description
Kyoto is a world-famous sightseeing city, and it is also known as a grid city. You come to Kyoto for sightseeing, and you plan to visit a famous attraction on foot. In this problem, we consider the following simplified setting.
In the city, there are east-west streets and north-south streets, so the city forms an grid. The intersection of the -th street from the north and the -th street from the west is called intersection .
Different streets may have different materials, widths, and crowd levels, so your walking speed may differ. For each street, your walking time is as follows:
-
If you walk one unit length along the -th street from the north, it takes seconds. That is, walking from intersection to intersection takes seconds.
-
If you walk one unit length along the -th street from the west, it takes seconds. That is, walking from intersection to intersection takes seconds.
You are currently at intersection and want to go to . You must walk along the streets, and you do not want to take detours, meaning you will not move north or west.
You want to arrive as early as possible. Please compute the minimum time needed to travel from intersection to intersection under the given conditions.
Input Format
The first line contains two integers , representing the numbers of streets.
The second line contains integers, where the -th integer represents the walking time on the -th east-west street from the north.
The third line contains integers, where the -th integer represents the walking time on the -th north-south street from the west.
Output Format
Output one integer in one line, representing the minimum walking time required.
2 2
1 3
2 5
5
5 5
7 1 5 2 8
7 2 4 1 6
20
4 6
454863204 543362989 866044086 813602010
71574269 17945210 688720933 392135202 38174709 168241720
2737473954
Hint
Sample Explanation #1
There are two routes from to :
- , which takes seconds.
- , which takes seconds.
Therefore, the minimum time is seconds.
This sample satisfies the constraints of all subtasks.
Sample Explanation #2
The optimal route is shown in the figure below:

This sample satisfies the constraints of all subtasks.
Sample Explanation #3
This sample satisfies the constraints of subtasks .
Constraints
For all testdata:
- .
- .
- .
The additional constraints and scores for subtasks are as follows:
| Subtask ID | Additional Constraints | Score |
|---|---|---|
| No additional constraints. |
Translated by ChatGPT 5