Tail of Snake

AtCoder
IDabc438_d
Time2000ms
Memory256MB
Difficulty
> Snuke is observing a snake and is curious about which parts are the head, body, and tail. He divided the snake into $N$ blocks and evaluated the head-likeness, body-likeness, and tail-likeness of each block. Then, he decided to find the division that maximizes the sum of the likeness values. You are given length-$N$ integer sequences $A = (A_1, A_2, \ldots, A_N)$, $B = (B_1, B_2, \ldots, B_N)$, and $C = (C_1, C_2, \ldots, C_N)$. Find the maximum possible value of $\displaystyle\sum_{i = 1}^{x} A_i + \sum_{i = x + 1}^{y} B_i + \sum_{i = y + 1}^{N} C_i$ for a pair of integers $(x, y)$ satisfying $1 \leq x < y < N$. ## Constraints * $3 \leq N \leq 3 \times 10^5$ * $1 \leq A_i, B_i, C_i \leq 10^6$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $A_1$ $A_2$ $\ldots$ $A_N$ $B_1$ $B_2$ $\ldots$ $B_N$ $C_1$ $C_2$ $\ldots$ $C_N$ [samples]
Samples
Input #1
5
1 4 2 4 3
2 3 4 2 2
3 2 4 4 3
Output #1
16

With $(x, y) = (2, 3)$, we have $\displaystyle\sum_{i = 1}^{x} A_i + \sum_{i = x + 1}^{y} B_i + \sum_{i = y + 1}^{N} C_i = 1 + 4 + 4 + 4 + 3 = 16$.
Input #2
3
1 1 1
1 1 1
1 1 1
Output #2
3
Input #3
6
2 10 7 7 7 11
5 7 9 10 9 12
6 6 7 10 12 7
Output #3
50
API Response (JSON)
{
  "problem": {
    "name": "Tail of Snake",
    "description": {
      "content": "> Snuke is observing a snake and is curious about which parts are the head, body, and tail. He divided the snake into $N$ blocks and evaluated the head-likeness, body-likeness, and tail-likeness of ea",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc438_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "> Snuke is observing a snake and is curious about which parts are the head, body, and tail. He divided the snake into $N$ blocks and evaluated the head-likeness, body-likeness, and tail-likeness of ea...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments