Easy to understand c++ solution
\nclass Solution {\npublic:\n    vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {\n        sort(items.begin(),items.end());\n      
```\nclass Solution {\npublic:\n    vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {\n        sort(items.begin(),items.end());\n        vector<int> arr1,arr2;\n        \n        for(int i=0;i<items.size();i++){\n            arr1.push_back(items[i][0]);\n            arr2.push_back(items[i][1]);\n        }\n        \n        vector<int> ret;\n        \n        vector<int>narr;\n        int maxm = 0;\n        \n        // creating a new array which stores maximum value till ith term;\n        for(int i=0;i<arr2.size();i++){\n            maxm = max(maxm,arr2[i]);\n            narr.push_back(maxm);\n        }\n        \n        for(int i =0;i<queries.size();i++){\n            int x = queries[i];\n            \n            auto l = lower_bound(arr1.begin(),arr1.end(),x+1);\n            int dis = l-1-arr1.begin();\n            \n            if(dis == -1) ret.push_back(0);\n            else ret.push_back(narr[dis]); // directly putting maximum value using the array which we created earlier\n        }\n        return ret;\n    }\n};\n```
[]