{"problem":{"name":"Sneaking","description":{"content":"On a two-dimensional plane, you are now at coordinate $(1, 1)$ and want to get to $(R, C)$, the coordinates of the UFO.   When you are at $(r, c)$, you can make the following four kinds of moves: *  ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"zone2021_e"},"statements":[{"statement_type":"Markdown","content":"On a two-dimensional plane, you are now at coordinate $(1, 1)$ and want to get to $(R, C)$, the coordinates of the UFO.  \nWhen you are at $(r, c)$, you can make the following four kinds of moves:\n\n*   Move from $(r, c)$ to $(r, c + 1)$ at the cost of $A_{r, c}$. You can make this move when $c < C$.\n*   Move from $(r, c)$ to $(r, c - 1)$ at the cost of $A_{r, c - 1}$. You can make this move when $c > 1$.\n*   Move from $(r, c)$ to $(r + 1, c)$ at the cost of $B_{r, c}$. You can make this move when $r < R$.\n*   Choose an integer $i$ such that $1 ≤ i < r$ and move from $(r, c)$ to $(r - i, c)$ at the cost of $1 + i$.\n\nFind the minimum cost needed to move from $(1, 1)$ to $(R, C)$.\n\n## Constraints\n\n*   All values in input are integers.\n*   $2 ≤ R, C ≤ 500$\n*   $0 ≤ A_{i,j} < 10^3$\n*   $0 ≤ B_{i,j} < 10^3$\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$R$ $C$\n$A_{1,1}$ $\\cdots$ $A_{1,C-1}$\n$\\vdots$\n$A_{R,1}$ $\\cdots$ $A_{R,C-1}$\n$B_{1,1}$ $\\cdots$ $B_{1,C}$\n$\\vdots$\n$B_{R-1,1}$ $\\cdots$ $B_{R-1,C}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"zone2021_e","tags":[],"sample_group":[["3 3\n10 1\n10 10\n1 10\n1 10 1\n1 10 1","9\n\nYou can achieve the cost of $9$ as follows:\n\n*   Move from $(1, 1)$ to $(2, 1)$ at the cost of $1$.\n*   Move from $(2, 1)$ to $(3, 1)$ at the cost of $1$.\n*   Move from $(3, 1)$ to $(3, 2)$ at the cost of $1$.\n*   Move from $(3, 2)$ to $(1, 2)$ at the cost of $3$.\n*   Move from $(1, 2)$ to $(1, 3)$ at the cost of $1$.\n*   Move from $(1, 3)$ to $(2, 3)$ at the cost of $1$.\n*   Move from $(2, 3)$ to $(3, 3)$ at the cost of $1$."],["7 11\n42 77 94 76 40 66 43 28 66 23\n27 34 41 31 83 13 64 69 81 82\n23 81 0 22 39 51 4 37 84 43\n62 37 82 86 26 67 45 78 85 2\n79 18 72 62 68 84 69 88 19 48\n0 27 21 51 71 13 87 45 39 11\n74 57 32 0 97 41 87 96 17 98\n69 58 76 32 51 16 38 68 86 82 64\n53 47 33 7 51 75 43 14 96 86 70\n80 58 12 76 94 50 59 2 1 54 25\n14 14 62 28 12 43 15 70 65 44 41\n56 50 50 54 53 34 16 3 2 59 88\n27 85 50 79 48 86 27 81 78 78 64","498"],["4 4\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0","0"]],"created_at":"2026-03-03 11:01:13"}}