New World
Practice
4.3 (55 votes)
Approved
Binary search
Easy
Greedy algorithms
Ready
Sorting
Problem
33% Success 3277 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

The time has arrived when the world is going to end. But don't worry, because the new world yuga will start soon. Manu (carrier of mankind) has been assigned the job to carry all the necessary elements of current yuga to the upcoming yuga.

There are N stones arranged in a straight line. In order to fulfill the task, Manu has to travel from the first stone to the last one in a very specific way. First of all, he has to do it using exactly K jumps. In a single jump, he can jump from a stone with coordinate xi to a stone with coordinate xj if and only if xi < xj. We denote the value xj - xi as the length of such a jump.

Your task is to help Manu minimize the maximum length of a jump he makes in his journey, in order to reach the last stone in exactly K jumps and save the mankind. This is the answer you have to provide.

Input:

In the first line, there is a single integer T denoting the number of test cases to handle. Then, description of T tests follow. In the first line of each such description, two integers N and K are given. This is followed by N space separated integers in the second line, each one denoting a single stone location.

Output:

Output exactly T lines, and in the ith of them, print a single integer denoting the answer to the ith test case.

Constraints:

1 <= T <= 10
2 <= N <= 105
1 <= K <= (N-1)
1 <= Coordinates of stones <= 109

Note:

  • It is not necessary that Manu steps on each stone.

  • Location of all stones are given in ascending order.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
49 votes
Tags:
AlgorithmsApprovedBinary SearchEasySearching
Points:30
20 votes
Tags:
Binary SearchEasySearching
Points:30
6 votes
Tags:
Binary SearchAlgorithmsC++