Created
January 17, 2026 07:55
-
-
Save maehrm/4f81c1e1591eaa841046ea0a3b9526f6 to your computer and use it in GitHub Desktop.
E - Hungry Takahashi https://atcoder.jp/contests/abc415/tasks/abc415_e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| H, W = map(int, input().split()) | |
| A = [list(map(int, input().split())) for _ in range(H)] | |
| P = list(map(int, input().split())) | |
| dp = [[float("inf")] * W for _ in range(H)] | |
| dp[H - 1][W - 1] = 0 | |
| for i in range(H - 1, -1, -1): | |
| for j in range(W - 1, -1, -1): | |
| if i + 1 < H: | |
| dp[i][j] = min(dp[i][j], dp[i + 1][j]) | |
| if j + 1 < W: | |
| dp[i][j] = min(dp[i][j], dp[i][j + 1]) | |
| dp[i][j] += P[i + j] - A[i][j] | |
| dp[i][j] = max(dp[i][j], 0) | |
| print(dp[0][0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment