Robberies
InterviewTime limit1sMemory limit256 MB
Pick a subset of banks that maximizes the stolen money while the combined capture probability stays strictly below the given limit.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Probability
- Solved
- No attempts yet
Problem
Roy plans to rob banks for a short while, then retire to a quiet job at a university. For months he has measured how much cash each bank holds and how risky it is to rob it.
His mother Ola set a limit on the risk she tolerates. Roy may rob any set of the banks, each bank at most once, as long as the probability that he is caught stays strictly below that limit. The banks are independent, so if he robs the set of banks, the probability of getting caught is .
Find the largest total amount of money Roy can take.
Input
The first line contains the number of test cases .
Each test case starts with a line holding a real number and an integer . is the limit Roy must stay below and is the number of banks he has plans for. Each of the next lines holds an integer and a real number . Bank holds millions, and robbing it has probability of getting caught.
- Every real number in the input has at most two digits after the decimal point.
A bank goes bankrupt once it is robbed, so Roy robs each bank at most once.
Output
For each test case print one line with the largest number of millions Roy can take while the probability of getting caught stays strictly below . If no set of banks meets that requirement, print 0.