Sorting +Prefix Sum + BinarySearch, JAVA, attention the overflow
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public List<Long> minOperations(int[] nums, int[] queries) {\n        List<Long> res = new ArrayList<>();\n        int n = nums.length;\n        long[] record = new long[n];\n        Arrays.sort(nums);      \n        record[0] = nums[0];\n        for(int i = 1; i < n; i++){\n            record[i] = record[i-1] + nums[i];\n        }\n        \n        \n        for(int i = 0; i < queries.length; i++){\n            long cur = 0;\n            int tmp = search(nums, queries[i]);\n            if(tmp == -1)tmp = 0;\n            cur += Math.abs(record[tmp] - (long)queries[i] * (tmp+1));\n            cur += Math.abs(record[n-1] - record[tmp] - (long)queries[i] * (n-tmp-1)); \n            res.add(cur);\n        }\n        return res;\n    }\n    \n    public int search(int[] arr, int target){\n        int left = 0, right = arr.length - 1;\n        while (left <= right) {\n            int mid = left + (right-left) / 2;\n            \n            if (arr[mid] == target) {\n                return mid;\n            } else if (arr[mid] < target) {\n                left = mid + 1;\n            } else {\n                right = mid - 1;\n            }\n        }\n        return right;\n    }\n}\n```
['Java']