This is a good problem that can be solved with some parallel programming.
F# makes this pretty easy. I’m not going post the entire solution, but just give an idea what F# can do to solve this problem a little faster. So after the list is sorted (assume the data is stored into an Array object)
input_array
|> Array.sort
|> Array.Parallel.mapi (func i e -> …)
i is the index into the array and e is the element
and the … is your “solution”.