


A book will be allocated to exactly one ninja.
At least one book has to be allocated to a ninja.
Allotment of the books should be done in a contiguous manner. For example, a ninja can not be allocated book 2 and book 4, skipping book 3.
The first line contains a single integer T representing the number of test cases.
The T-test cases are as follows:
The first line contains two space-separated integers ‘N’ and ‘B’ denoting the number of books, and the number of ninjas, respectively.
The second line contains N space-separated integers, where the ith element is the number of pages in the ith book.
The first and only line of output contains an integer denoting the minimum of the maximum number of pages allocated to a ninja.
The output of every test case is printed in a separate line.
Return -1 if it is impossible to allocate the books to all the ninjas.
1 <= T <= 10
1 <= N <= 10^4
1 <= B <= 10^2
0 <= pages <= 10^3
where T is the number of test cases, ‘N’ is the number of books, ‘B’ is the number of ninjas and ‘pages’ is the number of pages in each book.
Let’s look at both conditions:
Note that we can use any method for binary search( recursive / iterative ). In the code, we are using iterative binary search to improve the space complexity.
Element Count in Ranges
First Digit One
Minimize Maximum Adjacent Distance
Sorted Doubly Linked List to Balanced BST
Minimized Maximum of Products Distributed to Any Store