Two robots travel across the two-row grid, one after the other. Each starts at the upper-left cell and finishes at the lower-right cell, moving only right or down. The first robot removes all points from every cell on its path, including its starting and ending cells. The second robot then collects the remaining points along its own path; revisiting cells used by the first robot is allowed, but they now hold zero points. The first robot chooses a path to minimize the second robot's score, while the second chooses a path to maximize it. Return the second robot's score when both make optimal choices.
The first diagram hatches the first robot’s chosen path. After those cells become zero, the second diagram hatches a best path for the second robot.
Example 1:
Input: grid = [[1,4,2],[3,2,1]]
Output: 3Explanation: If the first robot moves down at column 1, the remaining grid is [[0,0,2],[3,0,0]]. The second robot can collect at most 3. Moving down at column 0 or 2 instead lets the second collect 6 or 5, so 3 is optimal.
Example 2:
Input: grid = [[5],[7]]
Output: 0Explanation: Both robots must visit both cells. The first clears them, leaving the second a score of 0.
Example 3:
Input: grid = [[1,1],[9,1]]
Output: 1Explanation: The first robot moves down immediately, clearing the entire bottom row and the first top cell. Only 1 point remains, which the second robot can collect by moving right before moving down.
Constraints:
grid.length == 2- Both rows have the same length, between
1and50000. 1 <= grid[r][c] <= 100000