Simple C++ || Well Explained ✅ || Faster then 99%
\n\n# Code\n\nclass Solution {\npublic:\n    vector<int> answerQueries(vector<int>& nums, vector<int>& queries) {\n        vector<int> ans;\n        sort(nums.b
\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> answerQueries(vector<int>& nums, vector<int>& queries) {\n        vector<int> ans;\n        sort(nums.begin(),nums.end());\n        for(int x:queries){\n            int sum=0;\n            int c=0;\n            for(auto y:nums){\n                if((sum+y)<=x){\n                    sum+=y;\n                    c++;\n                }\n            }\n            ans.push_back(c);\n        }\n        return ans;\n    }\n};\n```\n\nThis solution has a time complexity of O(nm) and a space complexity of O(nm), where n is the length of nums and m is the length of queries.\n\n\n\n
['Array', 'Binary Search', 'Greedy', 'Prefix Sum', 'C++']