Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
For each query, you should decrease all elements greater than queries[i] and increase all elements less than queries[i].
The answer is the sum of absolute differences between queries[i] and every element of the array. How do you calculate that optimally?