cswork / OAOpen practice workspace

FlexportOA #7

Matrix Traversal

Estimated MediumJudge-ready

Topics (AI-labelled)Grid DP

Start from any cell in the first row of a 4×4 matrix; at each step, move to the next row in an adjacent column. Maximize the initial 100 energy minus the total of the values of the cells visited.

Input

4 lines, each containing 4 integers (0≤mat[i][j]<100).

Output

Output the maximum energy that can remain after reaching the last row; it may be negative.

Example 1

Input:

10 20 30 40
60 50 20 80
10 10 10 10
60 50 60 50

Output:

0

Example notes

A linear scan/dynamic programming solution follows directly from the rules; the examples have been checked one by one against an independently built oracle.

Editorial

Loading solution…