#PS0000286. Trò chơi hai robot (Grid Game)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Trò chơi hai robot (Grid Game)
Grid Game
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Two robots traverse a positive-valued grid from the upper-left to the lower-right cell, moving only right or down. The first robot collects points and clears its entire path. The second then collects remaining points on its own path, which may intersect the first. The first minimizes the second robot’s maximum attainable score; the second maximizes its score. Compute that score.
Input
First line: . The next two lines each contain positive integers, the upper and lower rows respectively.
Output
Print the second robot's score under optimal play.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; the two rows are identical.
- Subtask 3 (50 points): ; .
Example 1
Input
3
2 5 4
1 5 1
Output
4
Explanation
Turning down at column 2 leaves 4 above and 1 below; robot 2 obtains 4. The other choices allow 9 and 6.
Example 2
Input
3
3 3 1
8 5 2
Output
4
Explanation
Turning down at the first column leaves 4 above. Turning later permits at least 8 points.
Example 3
Input
4
1 3 1 15
1 3 3 1
Output
7
Explanation
Turning down at the last column leaves 7 below. Earlier turns leave at least 15 above.