Assign each flavor malted or unmalted so every customer gets a liked type, minimizing malted batches, with at most one malted liked type per customer.
Medium5GreedyImplementationBrute forceMathInterviewNo attempts yetTime limit5sMemory limit512 MBYou run a milkshake shop. You can prepare N different flavors, and each flavor can be prepared malted or unmalted, so there are 2N different types of milkshake.
Each customer has a set of milkshake types they like, and a customer is satisfied if you have prepared at least one type from that set. At most one of the types a customer likes is malted.
You want to make N batches of milkshakes so that all of the following hold.
Decide whether you can satisfy every customer, and if you can, find which types you should make.
When every customer can be satisfied, the assignment that minimizes the number of malted batches is unique.
The first line contains the number of test cases C.
Each test case is given as follows.
All numbers on a line are separated by single spaces.
Print C lines, one per test case, in the order the test cases are given. Each line starts with Case #X: , where X is the test case number starting from 1. After that prefix, print the following.
IMPOSSIBLE if the customers' preferences cannot all be satisfied.In the first test case of the first example, flavor 1 must be malted to satisfy the first customer. Every other flavor can be unmalted. The second customer is satisfied by unmalted flavor 2, and the third customer is satisfied by unmalted flavor 5.
The second test case has only one flavor. One customer likes it malted and the other likes it unmalted, so you cannot satisfy both.