Kayaking Trip
Time limit2sMemory limit512 MB
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 that you have already worked out for each kayak. The final speed of a kayak also depends on the strengths and of the two people in it, by . The group has beginners with strength , normal participants with strength , and experienced kayakers with strength .
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 , , and , the number of beginners, normal participants, and experienced kayakers in that order. The total number of participants is even, at least , and at most .
The second line contains three integers , , and (), the strengths of the three kinds of participants in that order.
The third line contains integers (). Here is the speed factor of the th kayak.
Output
Print one integer, the maximum speed that the slowest kayak can reach.