C++ | MAP |SORTING | WITH EXPLANATION
PLEASE UPVOTE IF U LIKE MY SOLUTION AND EXPLANATION\n\n\nclass Solution {\npublic:\n    vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queri
***PLEASE UPVOTE IF U LIKE MY SOLUTION AND EXPLANATION***\n\n```\nclass Solution {\npublic:\n    vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {\n       \n        //map of the price and the maximum beauty of all the items below the price\n        map<int,int>mp2;\n        \n        //sort the items vector\n        sort(items.begin(),items.end());\n        \n        mp2[items[0][0]]=items[0][1];\n        for(int i=1;i<items.size();i++)\n        {\n            //just store the max_beauty(curr_it)=max(beauty(curr_it),beauty(prev_it));\n            //mp2[prev_it] stores the max beauty of all the items whose price are below prev_it(price)\n            mp2[items[i][0]]=max(items[i][1],mp2[items[i-1][0]]);\n        }\n        vector<int>res;\n        for(auto &it:queries)\n        {\n            //for each query we find the price<=query in the map\n            auto x=mp2.upper_bound(it);\n            \n            //if all prices are greater than the query then we return 0\n            if(x==mp2.begin()){res.push_back(0);continue;}\n            \n            //as upper_bound returns the next greater ele even if there is the el present \n\t\t\t//in the map so x-- points to the iterator<=query\n            x--;\n            \n            //just return the beauty associated with the iterator\n            res.push_back((*x).second);\n        }\n        return res;\n    }\n};\n```
['Sorting']