#P7793. Minimum Estimated Difficulty Sum

    ID: 20979 Type: Default 1000ms 256MiB

Minimum Estimated Difficulty Sum

Minimum Estimated Difficulty Sum

Each team member initially estimates the difficulty of each of n problems using integers from 1 to 5 (with larger numbers indicating higher difficulty). After that, the tasks are divided among the three team members by splitting the array of tasks into three non-empty consecutive segments. In doing so, the goal is to minimize the total estimated difficulty sum, where for each segment, only the difficulties estimated by its assigned team member are considered.

Formally, given three arrays a, b, and c of length n representing the estimated difficulties by person 1, person 2, and person 3 respectively, you are to choose two indices i and j such that:

[ 1 \le i < j < n, ]

and then assign:

  • Tasks 1 to i to the first member (using array a).
  • Tasks i+1 to j to the second member (using array b).
  • Tasks j+1 to n to the third member (using array c).

Your task is to compute the minimum possible sum:

[ \text{sum} = \left(\sum_{k=1}^{i} a_k\right) + \left(\sum_{k=i+1}^{j} b_k\right) + \left(\sum_{k=j+1}^{n} c_k\right). ]

</p>

inputFormat

The input consists of 4 lines:

  1. An integer n (where n ≥ 3), the number of tasks.
  2. n space-separated integers representing the estimates of the first team member.
  3. n space-separated integers representing the estimates of the second team member.
  4. n space-separated integers representing the estimates of the third team member.

outputFormat

Output a single integer, the minimum total estimated difficulty sum achievable by optimally splitting the tasks into three non-empty consecutive segments.

sample

3
1 2 3
3 2 1
2 2 2
5