### PROBLEM LINKS

### DIFFICULTY

MEDIUM

### EXPLANATION

At first sort all employees by the numbers **c*** in decreasing order. So we can assume that **c[0]>c[1]>…>c[n-1]**. If we choose some friendly group **i _{1}, i_{2}, …, i_{p}** then the quality of food in the kitchen will be

**2**. Since all

^{c}[i<sub>1</sub>]+2^{c}[i<sub>2</sub>]+…+2^{c}[i<sub>p</sub>]**c*** are different and

**2**then comparing friendly groups by food quality is equivalent to the lexicographical comparing.

^{i}> 2^{i-1}+…+2^{2}+2+1Hence we can use greedy strategy to find the best friendly group: at each step we must add to the group the employee which compatible with all employees in the group with the largest value of **c***. We can use several techniques in order to implement this approach efficiently. The simplest way is to loop through all employees and for each employee count the number of compatible with him employees that belong to the current friendly group. If this number coincides with the cardinality of the group then we add him otherwise not.

If we have some friendly group then in order to obtain next friendly group by the value of food quality we need to do the following. Throw away the last employee from the group and starting from the next employee follow the greedy strategy described above (in some cases you can’t add any employees after that but it’s fine it only means that the next friendly group is obtained by simply throwing away the last employee). Thus the overall complexity is **O(n log n + k (n+m) )**.

### SETTER’S SOLUTION

Can be found here.

### TESTER’S SOLUTION

Can be found here.