Ez solution
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:M*log(N) \n- no of queries == M and length of array is N\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    #define ll long long \n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        sort(nums.begin(),nums.end());\n        int n = nums.size();\n        vector<ll> ps(n+1,0);\n\n        for(int i = 0 ;i<n;i++){\n            ps[i+1] += nums[i]+ps[i];\n        }\n        nums.insert(nums.begin(),0);\n        n++;\n        vector<ll> ans ;\n        for(auto q : queries){\n            ll llind = lower_bound(nums.begin(),nums.end(),q)-nums.begin()-1;\n            ll uind = upper_bound(nums.begin(),nums.end(),q)-nums.begin();\n            ll val =  q*llind -( ps[llind] -ps[0]);\n            if(uind!=n){\n                val +=( ps[n-1] - ps[uind-1] )- q*(n-uind);\n            }\n            ans.push_back(val);\n        }\n        return ans; \n    }\n};\n```
['C++']