PEG Test '14 - Change

View as PDF

Submit solution

Points: 7
Time limit: 1.0s
Memory limit: 16M

Authors:
Problem type
PEG Test – Oct 3rd, 2014

After Korra's decision to leave the spirit world portals permanently open in support of having humans and spirits live in unity, Korra, Tenzin, and friends have decided to change the world once again. The harmonic convergence has gifted many people in the world with the power of airbending. Alas, people cannot control it. So, around a hundred years after their destruction, it's finally time for the air nation to be rebuilt.

However, the evil Red Lotus group consisting of Zaheer, Gazan, Ming-Hua, and P'Li has managed to take the group of new age airbenders hostage. Each of the four Red Lotus members has held an equal number of people hostage at different places in the temple. To save them, Team Avatar, consisting of Korra, Mako, Bolin, Asami, Lin, and Opal have closed in on the temple. Now, the team has to make some strategic decisions to save as many hostages as possible. Korra has to decide which members of the team (including herself) have to take on which members of the Red Lotus.

Zaheer, Gazan, Ming-Hua, and P'Li have strengths of Z, G, MH, and P (1 \le Z, G, MH, P \le 10^6) respectively. Korra, Mako, Bolin, Asami, Lin, and Opal have strengths of K, M, B, A, L, and O (1 \le K, M, B, A, L, O \le 10^6), respectively. Multiple people of Team Avatar may be assigned to the same Red Lotus member. The winner of a battle will be the side with the strictly larger total strength level. When more than one Team Avatar member is assigned to the same fight, their total strength will be the sum of the strengths of all members assigned.

Given the strengths of everybody, Korra would like to know the maximum number of battles they can win (between 0 and 4) if she assigned optimally.

Input Specification

Line 1: Four integers Z, G, MH, and P, representing the strengths of members of the Red Lotus.
Line 2: Six integers K, M, B, A, L, and O, representing the strengths of members of Team Avatar.

Output Specification

A single integer representing the maximum number of battles that can be won (0, 1, 2, 3, or 4) if Korra deploys Team Avatar members optimally.

Sample Input

25 15 20 25
20 10 10 5 15 15

Sample Output

3

Explanation

One possible way is by assigning: Korra to Gazan (20 > 15)
Mako, Bolin and Asami to Ming-Hua (10 + 10 + 5 > 20), and
Lin and Opal to P'Li (15 + 15 > 25).


Comments

There are no comments at the moment.