K-Triangles
Time limit3sMemory limit512 MB
Given an n by m integer matrix and k, find the maximum total sum of two non-overlapping k-triangles.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Prefix sum, Matrix
- Solved
- No attempts yet
Problem
You are given an matrix of integers and a positive integer .
For a cell of , the -triangles centered at are defined as follows.
- If and , then .
- If and , then .
- If and , then .
- If and , then .
The cost of a -triangle is .
Find the maximum possible total cost of two non-intersecting -triangles. Formally, find , where and are some -triangles.
Input
The first line contains three space-separated integers , , and (). Each of the next lines contains space-separated integers. The -th line contains (). It is guaranteed that there is at least one way to choose two non-intersecting -triangles in the matrix.
Output
Print a single integer: the maximum possible sum of costs of two non-intersecting -triangles.
Hint
In the second example, the answer is made up of two -triangles of type with centers at and .