simple and easy C++ solution || Binary Search 😍❤️‍🔥
if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n###### Let\'s Connect on LinkedIn: www.linkedin.com/in/shishirrsiam\n###### Let\'s Connect on Facebook: ww
# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n###### Let\'s Connect on LinkedIn: www.linkedin.com/in/shishirrsiam\n###### Let\'s Connect on Facebook: www.fb.com/shishirrsiam\n\n# Complexity\n- Time complexity: O(nlogn+mlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n+m)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int binarySearch(int val, vector<int>&pref)\n    {\n        int ans = 0, i = 0, j = pref.size()-1, mid;\n        while(i <= j)\n        {\n            mid = i + (j - i) / 2;\n            if(pref[mid] <= val)\n            {\n                ans = mid;\n                i = mid + 1;\n            }\n            else j = mid - 1;\n        }\n        return ans;\n    }\n    vector<int> answerQueries(vector<int>& nums, vector<int>& queries) \n    {\n        sort(begin(nums), end(nums));\n        vector<int>pref(1), ans;\n        for(auto val:nums)\n            pref.push_back(pref.back() + val);\n        for(auto val:queries)\n        {\n            int mx = binarySearch(val, pref);\n            ans.push_back(mx);\n        }\n        return ans;\n    }\n};\n```
['Array', 'Binary Search', 'Greedy', 'Sorting', 'Prefix Sum', 'C++']