Easy C++ Solution With Small Explanation
Intuition\nHere we have to do two things - first we have to find the price that is closest to the given query and then we have to find the maximum beauty.\n\n# 
# Intuition\nHere we have to do two things - first we have to find the price that is closest to the given query and then we have to find the maximum beauty.\n\n# Approach\nWe will sort the items first so that we can easily find the beauty for each index and then to apply binary search.\nFor the first part i.e. to search for the prices that is closest to the given query we can use binary search and then for finding the maximum beauty, we can store the maximum beauty till each index in a different array or in the same items array which will optimize memory.\n\n# Complexity\n- Time complexity:\nO(nlogn + mlogn)\n\n- Space complexity:\nO(1)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int binSearch(int num, vector<vector<int>>& items) {\n        int low = 0, high = items.size() - 1;\n        int ans = -1;\n        \n        while (low <= high) {\n            int mid = low + (high - low) / 2;\n            if (items[mid][0] <= num) {\n                ans = mid;\n                low = mid + 1;\n            } else {\n                high = mid - 1;\n            }\n        }\n        \n        return ans;\n    }\n    \n    vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {\n        sort(items.begin(), items.end());\n        \n        int maxBeauty = 0;\n        for (int i = 0; i < items.size(); ++i) {\n            maxBeauty = max(maxBeauty, items[i][1]);\n            items[i][1] = maxBeauty;//finding the beauty and placing them inplace without using extra memory\n        }\n        \n        vector<int> ans;\n        ans.reserve(queries.size()); \n        for (int query : queries) {\n            int index = binSearch(query, items);\n            if (index != -1) {\n                ans.push_back(items[index][1]);\n            } else {\n                ans.push_back(0);\n            }\n        }\n        \n        return ans;\n    }\n};\n```
['C++']