Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- testCases=int(input())
- for _ in range(testCases):
- N,C=[int(i) for i in input().split()]
- arr=[int(input()) for _ in range(N)]
- arr.sort()
- def ifpossible(C,mid):
- cow=1
- lastpos=0
- for i in range(1,len(arr)):
- if arr[i]-arr[lastpos]>=mid:
- cow+=1
- lastpos=i
- if cow>=C:
- return True
- return False
- strt=0
- end=arr[-1]
- ans=-1
- mid=(end+strt)//2
- while strt<=end:
- if ifpossible(C, mid):
- ans=mid
- strt=mid+1
- else:
- end=mid-1
- mid=(end+strt)//2
- print(ans)
- #**
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement