|
Otherwise, consider a grid with a wait time of \(A - (N + M - 2)\) for the top-left cell, a wait time of \(B - (N + M - 2)\) for the top-right cell, and wait times of \(1\) for all remaining cells. In such a grid, the minimum duration of a path from the top-left to the bottom-right corner includes the top-left cell along with \(K - 1\) cells with wait times of \(1\), for a total of \(A - (N + M - 2) + (N + M - 2) = A\). The minimum duration of a path from the top-right to the bottom-left corner is similarly \(B\). Therefore, such a grid constitutes a valid output. |