[Solution] Second Hands Meta Hacker Cup Qualification Round Solution
Sandy's store has pre-owned clock parts for sale, where the th part is of style . The store also has two display cases, each capable of holding at most parts. To maximize the aesthetics of Sandy's secondhand second hands, she'd like to put each of the parts into one of the two cases so that neither case ends up with two different parts of the same style, and neither case has more than parts total. Can you determine if this is possible?
Constraints
Input Format
Input begins with an integer , the number of test cases. For each test case, there is first a line containing space-separated integers, and . Then, there is a line containing
👇👇👇👇👇
space-separated integers, .
Output Format
For the th test case, print "Case #i: " followed by "YES" if it's possible to arrange the parts into two cases satisfying the description above, or "NO" otherwise.
Sample Explanation
In the first test case, there are parts of styles , , and , with the display cases having capacity . One solution, depicted below, is to put the first and third parts in one display case, and the second part in the other.
In the second test case, there are parts of styles , , , , , with the display cases having capacity . One solution, depicted below, is to put the first three parts in one display case, and the last two in the other.
In the third test case, there are parts, but the display cases can each only hold . Therefore, there is no solution.
In the fourth test case, style will always be duplicated in some display case for any given arrangement. Therefore, there is no solution.
No comments:
Post a Comment