C++ | Easy Sorting + Binary Search Solution | QlogN + NlogN
1) Sort in ascending order of price and beauty\n2) Now set the prefix max Beauty for each pair\n\nBefore Sorting \n1 2\t\n3 2\t\n2 4\t\n5 6\t\n3 5\t\n\n\nAfter 
1) Sort in ascending order of price and beauty\n2) Now set the prefix max Beauty for each pair\n\nBefore Sorting \n1 2\t\n3 2\t\n2 4\t\n5 6\t\n3 5\t\n\n\nAfter sorting \n1 2                          \n2 4                          \n3 2                          \n3 5                          \n5 6                          \n\n\nPrefix Max\n\n1 2\n2 4\n3 4\n3 5\n5 6\n\n\nFor each query , find the largest last pair whose price is less than equal to given value , and print the correspoding prefix max beauty.\n\n\n```\nclass Solution {\npublic:\n\n    vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {\n        sort(items.begin(),items.end());\n        int maxi = items[0][1];\n        // for(auto xt : items)\n        // {\n        //    cout<<xt[0]<<" "<<xt[1]<<endl;\n        // }\n        for(auto &xt : items)\n        {\n            maxi = max(maxi , xt[1]);\n            xt[1] = maxi;\n        }\n        // for(auto xt : items)\n        // {\n        //    cout<<xt[0]<<" "<<xt[1]<<endl;\n        // }\n        vector<int>ans;\n        int n = items.size();\n        \n        for(int key : queries){\n            int left = 0;\n            int right = n - 1;\n\n            int count = 0;\n\n            while (left <= right) {\n                int mid = (right + left) / 2;\n                if (items[mid][0] <= key) {\n                    count = mid + 1;\n                    left = mid + 1;\n                }\n                else\n                    right = mid - 1;\n            }\n            \n            if(count==0)\n                ans.push_back(0);\n            else\n                ans.push_back(items[count-1][1]);\n        }\n        return ans;\n    }\n};\n\n```\n
['Binary Search', 'C']