easy solution using binary search
\n\n# Complexity\n- Time complexity: O((N+M)Log(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# Complexity\n- Time complexity: O((N+M)Log(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```cpp []\nclass Solution {\npublic:\n    vector<int> answerQueries(vector<int>& nums, vector<int>& queries) {\n        sort(nums.begin(), nums.end());\n        int n = nums.size();\n\n        // creating prefix sum\n        vector<int> prefixSum(n);\n        int sum = 0;\n        for(int i = 0; i<n; i++){\n            sum += nums[i];\n            prefixSum[i] = sum;\n        }\n        \n        int m = queries.size();\n        vector<int> ans(m);\n        for(int i = 0; i<m ; i++){\n            // applying binary search on prefix sum\n            int lo = 0, hi = n-1;\n            while(lo<=hi){\n                int mid = lo + (hi-lo)/2;\n                if(prefixSum[mid]<=queries[i]){\n                    ans[i] = mid + 1;\n                    lo = mid + 1;\n                }\n                else hi = mid - 1;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']