Preparing NOJ

Meeting Schedule Arrangement

1000ms 65536K


Mr. Trasapong, the head of Computer Engineering Department, would like to have a meeting as soon as possible to address some issues of the department. However, other members in his department are so busy that it is very difficult to arrange their schedules for the meeting. So, in order to settle the meeting date, he requested every member to send back a list of convenient dates by E-mail. Your mission is to help him by writing a program that chooses the best date from the submitted lists. Your program should find the most convenient date for the most of the members. If there is more than one such day, the earliest is the best.


The input has multiple data sets, each starting with a line containing the number of members in the department and the quorum* of the meeting.


Here, N, meaning the number of the members in the department, and Q meaning the quorum, are positive integers. N is less than 20, and, of course, Q is less than or equal to N.

N lines follow, each describing convenient dates for a member in the following format.M Date1 Date2 ... DateM

Here, M means the number of convenient dates for the member, which is an integer greater than or equal to zero. The remaining items in the line are his/her dates of convenience, which are positive integers less than 31, that is, 1 means tomorrow, 2 means the day after tomorrow, and so on. They are in ascending order without any repetition and separated by a space character. Lines have neither leading nor trailing spaces.

A line containing two zeros indicates the end of the input. 


For each data set, print a single line containing the date number convenient for the largest number of members. If there is more than one such date, print the earliest. However, if no dates are convenient for more than or equal to the quorum number of members, print 0 instead. 

Sample Input:

3 2
2 1 4
3 3 4 8
3 2 
4 1 5 8 9 
3 2 5 9 
5 2 4 5 7 9 
3 3
2 1 4 
3 2 5 9 
2 2 4
3 3
2 1 2 
3 1 2 9 
2 2 4
0 0

Sample Output:




Note: quorum means the smallest number of the people who must present at a meeting. 

用于NUPT ACM 2010 Personal Ranking Contest 5

本题由旧版NOJ导入,来源:ACM-ICPC Thailand Southern Area Programming Contest 2010



Provider NOJ

Code NOJ1462


Submitted 1

Passed 1

AC Rate 100%

Date 04/20/2019 10:03:10


Nothing Yet