Easy, Beginner-Friendly - Beats 100%
\nclass Solution {\n    public List<Long> minOperations(int[] nums, int[] queries) {\n        int n = nums.length;\n        Arrays.sort(nums);\n        long[] s
```\nclass Solution {\n    public List<Long> minOperations(int[] nums, int[] queries) {\n        int n = nums.length;\n        Arrays.sort(nums);\n        long[] sum = new long[n + 1];\n        for (int i = 0; i < n; i++) {\n            sum[i + 1] = sum[i] + nums[i];\n        }\n        \n        List<Long> list = new ArrayList();\n        for (int q : queries) {\n            int lower = lowerBound(nums, q);\n            long res = 0;\n            res += (long) (lower - 0 + 1) * q - sum[lower + 1];\n            res += sum[n] - sum[lower + 1] - (long) (n - 1 - lower) * q;\n            list.add(res);\n        }\n        \n        return list;\n    }\n    \n    public int lowerBound(int[] nums, int q) {\n        int l = 0, r = nums.length - 1;\n        while (l <= r) {\n            int m = l + r >> 1;\n            if (nums[m] <= q) {\n                l = m + 1;\n            } else {\n               r = m - 1; \n            }\n        }\n        \n        return r;\n    }\n}\n\n//tc: O(nlogn)\n//sc: O(n)\n```
['Binary Search', 'Prefix Sum', 'Java']