File size: 1,270 Bytes
c4b0eef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
****************************************************************
****************************************************************
-> Coded by Stavros Chryselis				   
-> Visit my github for more solved problems over multiple sites 
-> https://github.com/StavrosChryselis			  
-> Feel free to email me at [email protected]	
****************************************************************
****************************************************************
*/

#include <stdio.h>
#include <vector>
#include <algorithm>
 
using namespace std;
 
vector<int> A;
int N, M;
 
inline bool check(int x, int m)
{
	int i=1;
	int curr=A[0];
	m--;
	while(m>0)
	{
		if(A[i]-curr>=x)
		{
			m--;
			curr=A[i];
		}
		i++;
		if(m>0 && i>=N)
			return 0;
	}
 
	return 1;
}
 
void init()
{
	int i, num;
 
	A.clear();
 
	scanf("%d %d", &N, &M);
 
	for(i=0; i<N; i++)
	{
		scanf("%d", &num);
		A.push_back(num);
	}
 
	sort(A.begin(), A.end());
 
	num=A[A.size()-1];
}
 
 
int main()
{
	int T;
	int begin, end, mid;
 
	//freopen("input.txt","r",stdin);
	scanf("%d", &T);
 
	while(T--)
	{
		init();
		begin=1;
		end=A[N-1]-A[0];
		while(end!=begin+1)
		{
			mid=(begin+end)/2;
			if(check(mid, M))
				begin=mid;
			else
				end=mid;
		}
 
		printf("%d\n", begin);
 
		
	}
 
	return 0;
}