#P2392. Dual Brain Exam Revision Scheduling

    ID: 15663 Type: Default 1000ms 256MiB

Dual Brain Exam Revision Scheduling

Dual Brain Exam Revision Scheduling

In the final exam, kkksc03 needs to revise 4 subjects. Each subject has its own problem set. Specifically, the four subjects have s1, s2, s3, s4 problems respectively. For the first subject, the problems take A_1, A_2, \ldots, A_{s_1} time units; for the second subject, they take B_1, B_2, \ldots, B_{s_2} time units; for the third subject, C_1, C_2, \ldots, C_{s_3}; and for the fourth subject, D_1, D_2, \ldots, D_{s_4}.

kkksc03 has a unique ability: his two brains can compute 2 different problems simultaneously, but only if the problems belong to the same subject. Moreover, he must revise one subject at a time.

For each subject, the problems can be processed in parallel on 2 'processors' (the two brains). The minimal time to finish one subject is the minimum possible maximum sum when dividing the problem times into two groups. Formally, for a subject with tasks having times \(t_1, t_2, \ldots, t_n\), if we partition the tasks into two sets \(S_1\) and \(S_2\), then the time taken is

[ T = \max\Bigl(\sum_{i \in S_1} t_i,; \sum_{i \in S_2} t_i\Bigr)]

The overall minimal time to complete the revision is the sum of the minimal times of all 4 subjects.

Your task is to compute and output the minimum total time required for kkksc03 to finish his revision.

inputFormat

The first line contains 4 integers s1 s2 s3 s4 --- indicating the number of problems in each subject.

The next 4 lines describe the problem times for each subject in order:

  • The second line contains s1 integers, representing A1, A2, \ldots, As₁.
  • The third line contains s2 integers, representing B1, B2, \ldots, Bs₂.
  • The fourth line contains s3 integers, representing C1, C2, \ldots, Cs₃.
  • The fifth line contains s4 integers, representing D1, D2, \ldots, Ds₄.

You can assume that all numbers are positive integers.

outputFormat

Output a single integer --- the minimum total time required to complete the revision across all subjects.

sample

2 1 1 1
3 1
4
2
5
14