C++||Most Easy Solution Using Prefix & Suffix Sum and Binary Search
\ntypedef long long ll;\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        ll m=nums.size();\n 
```\ntypedef long long ll;\nclass Solution {\npublic:\n    vector<long long> minOperations(vector<int>& nums, vector<int>& queries) {\n        ll m=nums.size();\n        sort(nums.begin(),nums.end());\n        vector<ll> suff(m,0);\n        vector<ll>pref(m,0);\n        vector<ll> ans;\n        suff[m-1]=nums[m-1];\n        pref[0]=nums[0];\n        for(int i=m-2;i>=0;i--)\n        {\n            suff[i]=nums[i]+suff[i+1];// calculating the suffix sum\n        }\n        for(int i=1;i<m;i++)\n            pref[i]=pref[i-1]+nums[i];// calculating the prefix sum\n        for(int i=0;i<queries.size();i++)\n        {\n           ll ind=lower_bound(nums.begin(),nums.end(),queries[i])-nums.begin();\n            ll inl=ind*queries[i]*1LL; // no of elements to left of index is ind\n            ll rl=(m-ind)*queries[i]*1LL;//no of elements to right of index is m-ind where m is no of elements present in array\n\t\t\t                                          //multiplying with queries[i] gives the sum required\n            ll sum=0;\n            // cout<<ind<<endl;\n            //cout<<inl<<" "<<rl<<endl;\n            if(ind==m)\n            {\n                ans.push_back(inl-pref[m-1]);\n                continue;\n            }\n            if(ind-1>=0)\n            {\n                sum+=(inl-pref[ind-1]);\n            }\n            sum+=(suff[ind]-rl);\n            ans.push_back(sum);\n        }\n        return ans;\n    }\n};\n```
['Binary Search', 'Prefix Sum']