This solution is very beginner friendly.
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 {\npublic:\n    vector<long long> minOperations(vector<int>& nums,vector<int>& queries) {\n        vector<long long> answer;\n        int n = nums.size();\n        vector<long long> presum(n);\n\n        long long inc = 0;\n        long long dec = 0;\n        long long value = 0;\n\n        sort(nums.begin(), nums.end());\n\n        presum[0] = nums[0];\n        for(int i = 1; i < n; i++){\n            presum[i] = presum[i-1] + nums[i];\n        }\n\n        for(auto q : queries){\n            int s = 0;\n            int e = n-1;\n            int mid;\n            value = q;\n\n            while(s <= e){\n                mid = s + (e-s)/2;\n                if(nums[mid] <= value){\n                    s = mid+1;\n                }\n                else{\n                    e = mid-1;\n                }\n            }\n\n            inc = 0;\n            dec = 0;\n\n            if(s > 0){\n                inc = abs((value * s) - presum[s-1]);\n            }\n            \n            if(s == 0){\n                dec = abs(value*n - presum[n-1]);\n            }\n            else{\n                dec = abs((value * (n-s)) - (presum[n-1]-presum[s-1]));\n            }\n\n            answer.push_back(inc + dec);\n        }\n        return answer;\n    }\n};\n```\n\nPlease upvote my solution and share it.
['C++']