Optimized Java solution || Binary Search || Prefix Sum
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$$O(q*log(n))$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n# Code\n```\nclass Solution {\n    public List<Long> minOperations(int[] nums, int[] q) {\n        int n = nums.length;\n        Arrays.sort(nums);\n    \n        List<Long> ans = new ArrayList<>();\n\n        long[] prefix = new long[n+1];\n        for(int i = 1; i <= n; i++) {\n            prefix[i] = prefix[i-1] + nums[i-1];\n        }\n\n        for(int val : q) {\n            int i = Arrays.binarySearch(nums, val);\n            if(i < 0) i = -(i + 1);\n            ans.add(1L * val * (2*i-n) + prefix[n] - 2 * prefix[i]);\n        }\n        return ans;\n    }\n}\n```
['Array', 'Binary Search', 'Sorting', 'Prefix Sum', 'Java']