Kayaking Trip

Time limit2sMemory limit512 MB

Summary
Given counts of three strength levels and kayak speed factors, pair everyone two to a kayak to maximize the slowest kayak's speed.
Level

Medium7 of 10

Topics
Greedy, Sorting, Binary search, Two pointers
Solved
No attempts yet

Problem

You are leading a kayaking trip in the Stockholm archipelago with a group of mixed ability. Just as you are about to start the final stretch back to the mainland, a storm appears on the horizon. You have to paddle as fast as you can so that nobody gets trapped on one of the islands. You cannot leave anyone behind, so the speed of the group is the speed of the slowest kayak.

The kayaks are of different types and carry different amounts of packing, so some are easier to paddle than others. That difference is captured by a speed factor cc that you have already worked out for each kayak. The final speed vv of a kayak also depends on the strengths s1s_1 and s2s_2 of the two people in it, by v=c(s1+s2)v = c(s_1 + s_2). The group has beginners with strength sbs_b, normal participants with strength sns_n, and experienced kayakers with strength ses_e.

Work out how fast the slowest kayak can go when you split the participants two to a kayak.

Input

The first line contains three non-negative integers bb, nn, and ee, the number of beginners, normal participants, and experienced kayakers in that order. The total number of participants b+n+eb + n + e is even, at least 22, and at most 100000100000.

The second line contains three integers sbs_b, sns_n, and ses_e (1≤sb<sn<se≤10001 \le s_b < s_n < s_e \le 1000), the strengths of the three kinds of participants in that order.

The third line contains m=(b+n+e)/2m = (b + n + e) / 2 integers c1,…,cmc_1, \dots, c_m (1≤ci≤1000001 \le c_i \le 100000). Here cic_i is the speed factor of the iith kayak.

Output

Print one integer, the maximum speed that the slowest kayak can reach.

Examples2

  1. Example 1

    Input
    3 1 0
    40 60 90
    18 20
    
    Expected output
    1600
    
  2. Example 2

    Input
    7 0 7
    5 10 500
    1 1 1 1 1 1 1
    
    Expected output
    505