✅ Efficient Solution with Prefix Sums and Binary Search in C++🚀🔥
Code
# Code
```cpp []
class Solution {
public:
    vector<int> answerQueries(vector<int>& nums, vector<int>& queries) {
        int n = nums.size();//[4,5,2,1] = 4 
        int m = queries.size();//[3,10,21] = 3 
        sort(nums.begin(),nums.end());//[1,2,4,5]
        vector<int>ans(m);
        
        for(int i = 1 ; i < n ; i++){
            nums[i] = nums[i]+nums[i-1] ;
        }
        for(int i = 0 ; i < m ; i++){
            int maxlen = 0 ;
          int lo = 0 ; 
          int hi = n-1 ;
          while(lo<=hi){
            int mid = lo + (hi-lo)/2;
            if(nums[mid]>queries[i])hi=mid-1 ;
            else{
                maxlen  = mid + 1 ;
                lo = mid + 1 ;
            }
          }
            ans[i] = maxlen ;
        }
        // prefix : 1,3,7,12 ;
         
    return ans ;
    }
};
```
['Array', 'Binary Search', 'Sorting', 'Prefix Sum', 'C++']