C++ Easy Solution || Beats 100% || Binary Search Approach || 🔥🔥
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    int f(vector<int> &nums,int temp)\n    {\n        int n = nums.size();\n        int ans=-1;\n        int l=0,h=n-1;\n        while(l<=h)\n        {\n            int m = (l+h)/2;\n            if(nums[m]>=temp)\n            {\n                ans=m;\n                h=m-1;\n            }\n            else\n            l=m+1;\n        }\n        return ans;\n    }\n\n    vector<long long> minOperations(vector<int>& nums, vector<int>& q) {\n        int n = nums.size();\n        int m = q.size();\n        vector<long long> v;\n        sort(nums.begin(),nums.end());\n        vector<long long> p(n+1, 0);\n        for(int i=0;i<n;i++)\n        {\n            p[i+1] = p[i]+nums[i];\n        }\n        for(auto it:q)\n        {\n            if(it<nums[0] || it>nums[n-1])\n            {\n                v.push_back(abs(p[n]-(it*1LL*n)));\n                continue;\n            }\n            int temp = f(nums,it);\n            long long sum = abs(p[temp]-(temp*1LL*it))+abs(p[n]-p[temp]-((n-temp)*1LL*it));\n            v.push_back(sum);\n        }\n        return v;\n    }\n};\n```
['Binary Search', 'C++']