Grades
InterviewTime limit1sMemory limit1024 MB
Given an N by N grid of scores, find the largest pocket money left after deleting one rectangular sub-table, where each score adds (score minus 50).
- Level
Medium5 of 10
- Topics
- Matrix, Dynamic programming, Prefix sum
- Solved
- No attempts yet
Statement
Juku has taken several tests at school, and each test is graded from points.
Juku's grandfather gives him pocket money based on his grades. He treats a score above 50 as a good grade and a score below 50 as a bad grade. Specifically, he adds the part of each score above 50 to the pocket money and subtracts the part below 50. For example, with scores 35, 42, 81, and 100, Juku receives euros. A test scored exactly 50 does not change the pocket money.
The teacher records Juku's scores in an Excel table with rows and columns, so Juku has scores in total. Juku can access the table once and change his grades. He selects one rectangular sub-table (it may be empty, that is, contain zero cells) and deletes all the grades in it.
Find the maximum amount of pocket money Juku can receive after such a deletion.
Input
The first line contains an integer (), the side length of the teacher's table.
Each of the next lines contains integers from to , separated by spaces. These are Juku's grades.
Output
Print one integer: the maximum amount of pocket money Juku can receive.