Given each dancer's total of three judge scores and a budget of surprising triplets, maximize the count of dancers whose best score reaches p.
Medium4GreedyMathNo attempts yetTime limit5sMemory limit512 MBYou are watching a show where Googlers (Google employees) dance. After a dance, three judges each give the dancer one score, and those three scores form one group. Every score is an integer from 0 to 10. The judges use very similar standards, so a group is called surprising when it holds two scores that differ by exactly 2. Two scores that differ by more than 2 never appear in the same group.
For example, (8,8,8) and (7,8,7) are not surprising, while (6,7,8) and (6,8,8) are surprising. (7,6,9) never appears.
A Googler's total points is the sum of the three scores in that Googler's group, and the best result is the largest of those three scores. Given the total points of every Googler and the number of surprising groups, find the largest number of Googlers who could have had a best result of at least p.
Consider 6 Googlers whose total points are 29, 20, 8, 18, 18, 21 in that order. There were 2 surprising groups, and you want to know how many Googlers could have had a best result of 8 or more. The groups can be chosen like this.
10 9 10
6 6 8 (*)
2 3 3
6 6 6
6 6 6
6 7 8 (*)
The two lines marked with a (*) are the surprising groups. Here 3 Googlers received a score of 8 or more. No choice of groups gives more than 3, so the answer is 3.
The first line contains the number of test cases T. Each of the next T lines holds one test case as integers separated by single spaces. The first integer is the number of Googlers N, the second is the number of surprising groups S, and the third is p as described above. The next N integers ti are the total points of the Googlers.
For each test case, print one line in the form Case #x: y, where x is the test case number starting from 1 and y is the largest number of Googlers who could have had a best result of at least p.