Locked Treasure
Time limit1sMemory limit256 MB
Given n bandits and threshold m, compute the fewest locks whose keys allow every group of m or more members to open the door but no smaller group to do so.
- Level
Medium7 of 10
- Topics
- Combinatorics
- Solved
- No attempts yet
Problem
A group of bandits () hid their stolen treasure in a room. The treasure stays locked away until someone needs to retrieve it. The bandits do not trust each other, so they want a rule that at least of them () must agree before the treasure comes out.
They decided to put several locks on the door, and the door opens only when every lock is open. Each lock can have up to keys, handed out to some of the bandits. A group opens a given lock only if at least one bandit in the group holds a key to it.
You are given and . Find the minimum number of locks such that the keys can be distributed so that every group of or more bandits opens all the locks, and no smaller group opens all the locks.
For example, with and , three locks are enough. Give the keys of lock 1 to bandits 1 and 2, the keys of lock 2 to bandits 1 and 3, and the keys of lock 3 to bandits 2 and 3. A single bandit cannot open all the locks, and any two bandits together can. Two locks are not enough to meet the requirement.
Input
The first line contains a positive integer, the number of test cases. Each test case is one line holding the two integers and .
Output
For each test case, print the minimum number of locks needed on its own line.