How to count maximum number of pairs from an array with difference at least K with no element repeating

for eg , A = {9,1,2,5,5,7,2,1,1} diff = 4
Maximum number of pairs that can be formed at a time are 4 . i.e {5,1} {5,1} {7,1} {9,2}