{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"As the \u0027Harry Potter\u0027 series is over, Harry has no job. As he wants to make quick money, (he wants everything quickly!), he decided to rob banks. He wants to take calculated risks, and grab as much money as possible. But his friends - Hermione and Ron have decided upon a tolerable probability **P** of getting caught. They feel that it would be safer if he robs a subset of the banks under probablity **P**."}},{"title":"Input","value":{"format":"MD","content":"Input starts with an integer **T (\u0026#8804; 100)**, denoting the number of test cases.\n\nEach case contains a real number **P**, the probability as described above, and an integer **N (0 \u0026lt; N \u0026#8804; 100)**, the number of banks he is planning to rob.\n\nThen follow **N** lines, where line **j** gives an integer **M\u003csub\u003ej\u003c/sub\u003e (0 \u0026lt; M\u003csub\u003ej\u003c/sub\u003e \u0026#8804; 100)** and a real number **p\u003csub\u003ej\u003c/sub\u003e** . Bank **j** contains **M\u003csub\u003ej\u003c/sub\u003e** million dollars, and the probability of getting caught if he decides to rob bank j is **p\u003csub\u003ej\u003c/sub\u003e**. A bank goes bankrupt if it is robbed, and you may assume that all the given probabilities are independent."}},{"title":"Output","value":{"format":"MD","content":"For each case, print the case number and the maximum number of millions he can expect to get while the probability of getting caught is less than **P**."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3\n0.04 3\n1 0.02\n2 0.03\n3 0.05\n0.06 3\n2 0.03\n2 0.03\n3 0.05\n0.10 3\n1 0.03\n2 0.02\n3 0.05\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1: 2\nCase 2: 4\nCase 3: 6\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"MD","content":"For the first case, if he wants to rob bank 1 and 2, then the probability of getting caught is **0.02 + (1 - 0.02) * .03 \u003d 0.0494** which is greater than the given probability **(0.04)**. That\u0027s why he has only option, just to rob rank 2."}}]}