Beats 99.6%🔥🔥🔥Very EASY to UNDERSTAND PREFIX SUM+SORTING approach.
\n\n# Complexity\n- Time complexity:\n O(nlogn) \n\n- Space complexity:\n O(n) \n\n# Code\n\nclass Solution {\npublic:\n    vector<int> answerQueries(vector<int
\n\n# Complexity\n- Time complexity:\n $$O(nlogn)$$ \n\n- Space complexity:\n $$O(n)$$ \n\n# Code\n```\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        vector<int>pf(n);\n\n        for(int i=0;i<n;i++)\n        pf[i]=(i?pf[i-1]:0)+nums[i];\n        vector<int>ans;\n        for(auto i:queries)\n        {\n            int j=upper_bound(pf.begin(),pf.end(),i)-pf.begin();\n            j--;\n            ans.push_back(j+1);\n        }\n        return ans;\n    }\n};\n```
['Binary Search', 'Prefix Sum', 'C++']