Phoenix and Dalgu
Time limit1.5sMemory limit1024 MB
Dalgu blocks one K by K square avoiding the two corners, and the task is to find the largest-weight monotone path from (1,1) to (N,N) under the best such block.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Prefix sum, Matrix
- Solved
- No attempts yet
Problem
Phoenix and Dalgu play a game on an grid. Cell has weight . The game goes as follows.
- Dalgu picks one square region and gives all cells in it to Yooni. However, the chosen region must not contain cell or cell .
- Phoenix starts at cell and moves until reaching cell . From cell , Phoenix can move to or . Phoenix cannot move outside the grid or onto cells given to Yooni.
- Phoenix's score is the sum of the weights of the cells Phoenix passes through.
Phoenix wants the score to be as large as possible, and Dalgu chooses the region to make it as small as possible. Assuming both play optimally, find the maximum score Phoenix can obtain.
Input
The first line contains two integers and , separated by a space. (; )
Each of the next lines contains integers , separated by spaces. ()
Output
Print the maximum score Phoenix can obtain.