MicrosoftOA #54
Optimal Path in a Grid
Estimated EasyJudge-ready
Topics (AI-labelled)Grid DPPrefix & Ranges
Go from the first cell of the top row to the last cell of the bottom row, moving only right or down, and minimize the maximum number along the path.
This site uses a standard input/output protocol.
Input
The first line contains N, followed by two lines containing A and B respectively. This site uses 1≤N≤200000 and numbers in −10⁹..10⁹.
Output
Output a single integer, the answer.
Example 1
Input:
3
3 4 6
6 5 4
Output:
5
Example 2
Input:
6
1 2 1 1 1 4
1 1 1 3 1 1
Output:
2
Example 3
Input:
1
-3
-5
Output:
-3
Example notes
Example 1: move down at the middle column, passing 3, 4, 5, 4, for a maximum of 5. Example 2: move down to the right of the 3 in the bottom row, avoiding the 4 in the top row; the maximum is 2. Example 3: the path must pass through −3 and −5, so the maximum is −3.
Editorial
Loading solution…