Sorting || Prefix sum|| (nlogn)
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:$$O(nlog( n))$$ \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            int n=nums.size();\n            sort(nums.begin(),nums.end());\n            vector<long long>presum;\n            long long sum=0;\n            presum.push_back(sum);\n            for(auto it:nums)\n             {\n                sum+=it;\n                presum.push_back(sum);\n             }\n              int m=presum.size();\n             vector<long long >ans;\n             for(int i=0;i<queries.size();i++){\n                int ind= lower_bound(nums.begin(),nums.end(),queries[i])-nums.begin();\n                cout<<ind<<endl;\n                if(ind==0){\n                    long long sum=presum[m-1]-presum[0];\n                    long long req=static_cast<long long>(queries[i])*(n-ind);\n                    ans.push_back(sum-req);\n                }\n                else if(ind==n){\n                    long long req=static_cast<long long>(queries[i])*n;\n                    long long sum=presum[m-1];\n                    ans.push_back(req-sum);\n                }\n                else {\n                    long long sum1=static_cast<long long> (queries[i])*(ind)-presum[ind];\n                    long long sum2= presum[m-1]-presum[ind]-static_cast<long long>(queries[i])*(n-ind);\n                    ans.push_back(sum1+sum2);\n\n                }\n             }\n\n             return ans;\n\n    }\n};\n```
['C++']