|
|||
A Matchmaking Problem
Matchmaking is a tough job, and even then, its long-term success (a happy family) depends on two people who are often not involved in the matchmaking process. But now, sites like Facebook, Twitter and communication devices/software like mobile phones, messengers have made the professional matchmakers jobless. So these angry and jobless matchmakers have gathered together to make the government pass a law in the parliament that will stop people from choosing their life partners. The law is stated below: In a certain community, the most senior bachelor must marry a spinster (female bachelor) whose age is nearest to him. The next senior bachelor will then marry a spinster whose age is nearest to him (of course, if there is a tie, marrying any one of them will do) excluding the spinster that has already got married. This process continues until there is no bachelor or spinster left. Of course, a bachelor cannot marry two spinsters, and a spinster cannot marry two bachelors. For example, in a community there are four bachelors who are 21, 25, 26, and 2 years old and four spinsters who are 23, 24, 25, and 35 years old. The diagram below shows the only possible way of marriages (e.g., the 26-year-old bachelor marries the 25-year-old spinster, and so on):
Now, given the ages of the bachelors and the spinsters in a community, you will have to find the number of bachelors left, after all the marriages have taken place according to the law mentioned above. Also, you have to report the age of the youngest bachelor left in the community if there is one. Input SpecificationThe input contains at most 25 test cases. The description of each test case is given below: The first line of each test case contains two integers B (0 < B < 10000) and S (0 < S < 10000), which denote the total number of bachelors and spinsters in the community, respectively. Each of the next B lines contains one integer between 2 and 60 (inclusive), which denotes the age of one bachelor in the community. Each of the next S lines contains one integer between 2 and 60 (inclusive), which denotes the age of one spinster in the community. For simplicity, you don't need to worry about getting married at a very small age in this problem. That means unmarried people of all ages are valid bachelors or spinsters. The input is terminated by a line containing two zeroes. Output SpecificationFor each test case, produce one line of output. This line contains the case number followed by one or two integers. The first integer denotes the number of bachelors left in the community after all potential marriages have been completed. If this integer is not zero, then print a second integer denoting the age of the youngest bachelor left in the community after all possible marriages have been completed. Look at the output for sample input for details. Sample Input
Output for Sample Input
|
|||
University of Debrecen; Faculty of Informatics; v. 09/30/2024 |