JAVA SOLUTION 100% FASTER || BinarySearch
Search for all the numbers smaller than the query element the sum total should be number of element*query if sum of all smaller elements is  less then we need t
**Search for all the numbers smaller than the query element the sum total should be number of element*query if sum of all smaller elements is  less then we need to add the difference number of time  And in the case of larger element we need to subtract the Sum total from sum of larger elements!!!**\n```\nclass Solution {\n    public List<Long> minOperations(int[] nums, int[] queries) {\n        int n=nums.length;\n        Arrays.sort(nums);\n        long prefix[]=new long[n];\n        ArrayList<Long> list=new ArrayList<>();\n        prefix[0]=nums[0];\n        for(int i=1;i<nums.length;i++){\n            prefix[i]=prefix[i-1]+nums[i];\n        }\n        for(int i=0;i<queries.length;i++){\n            int l=0;\n            int r=n-1;\n            long max=(long)queries[i]*n;\n            while(l<r){\n                int mid=(l+r)>>1;\n                if(nums[mid]<queries[i]){\n                    l=mid+1;\n                }\n                else{\n                    r=mid;\n                }\n            }\n\t\t\t//no smaller element\n            if(l<=0){\n                long diff=(long)Math.abs(prefix[n-1]-max);\n                list.add(diff);\n                continue;\n            }\n\t\t\t//all smaller\n            if(l>=n-1){\n                long diff=(long)Math.abs(max-prefix[n-1]);\n                list.add(diff);\n                continue;\n            }\n            else{\n                int lowerHalfEnd=l;\n                if(nums[l]!=queries[i]){\n                    lowerHalfEnd=l-1;\n                }\n                long smallerMax=(long)queries[i]*(lowerHalfEnd+1);\n                long LargerMax=(long)queries[i]*(n-lowerHalfEnd-1);\n                long total=(long)(smallerMax-prefix[lowerHalfEnd])+(prefix[n-1]-prefix[lowerHalfEnd]-LargerMax);\n                list.add(total);\n            }\n        }\n        return list;   \n    }\n}\n```
['Binary Search', 'Sorting', 'Prefix Sum', 'Java']