Maximum Operation Count
89% Success1544 Attempts30 Points1s Time Limit256MB Memory1024 KB Max Code
We have given an array \(nums\) of integers of size \(N\) and a positive integer \(K\). We can perform as many operations on the array till it has at least two elements.
The operation is as follows: you can pick any two numbers from the array and remove both if the difference between them is at least \(K\).
Find the maximum number of times we can perform this operation on the array.
Input format
- The first line contains two space-separated integers \(N\) and \(K\).
- The second line contains \(N\) space-separated integers denoting array \(nums\).
Output format
- Print the maximum possible number of operations.
Constraints
- \(1 \leq N \leq 10^6 \)
- \( 1 \leq K, nums[i] \leq 10^6 \)
Examples
Input
6 3 1 5 2 3 4 1
Output
2
Explanation
One of the possibility for performing maximum number of operation on given array.
After 1st operation \(nums\) = [1,2,3,5].
After 2nd operation \(nums\) = [2,3].
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 Editor...
Results