Medium Search Techniques > Binary Search/Bisection

**Mr BBK** don’t fall into sleep before 2 PM. So, His mother suggested him to count numbers in reverse order. It is guaranteed that he fall into sleep if he counts at least 20000 numbers sequentially in reverse order. Every number have **Sleepiness** value. When he pronounce/call the number, he gains Sleepiness value of that number. If summation of Sleepiness value >= **K** , he fall into sleep. Counting a number takes one second. His target is to fall into sleep as early as possible. He wants help to find the **minimum time** needed to fall into sleep for Mr BBK. He can choose any number <= 20000 and starts counting numbers in reverse order sequentially. He stops counting automatically when he fall into sleep. Input: ------ This is a smaple input detail. Please put your input detail here. For example, Input starts with an integer **T (1<=50)**, denoting the number of test cases. Each case contains a non-negative integer **K**. The next line will contain **20000** integers separated by spaces, denoting the Sleepiness values of the numbers from 1 to 20000. **Constraints** 1<=Sleepiness value <= 20000 0<= K <= ( Sum of Sleepiness values from 1 to 20000 ) Output: ------- For each test case, print the minimum time needed to fall into sleep for Mr BBK. Sample Input ------------ 1 2546 8 50 74 59 31 73 45 79 24 10 41 66 93 43 88 4 28 30 41 13 4 70 10 58 61 34 100 79 17 36 98 27 13 68 11 34 80 50 80 22 68 73 94 37 86 46 29 92 95 58 2 54 9 45 69 91 25 97 31 4 23 67 50 25 2 54 78 9 29 34 99 82 36 14 66 15 64 37 26 70 16 95 30 2 18 96 6 5 52 99 89 24 6 83 53 67 17 38 39 45 **Note** : Sample input is only for testing your code, it contains only Sleepiness value up-to 100. Sample Output ------------- 50

Bir Bahadur Khatri