C++ | Easy to understand | Sorting + Map | 100% faster | 356 MS Solution
\n\nstatic const auto Initialize = []{\n    ios::sync_with_stdio(false); cin.tie(nullptr);\n    return nullptr;\n}();\nclass Solution {\npublic:\n    vector<int
\n```\nstatic const auto Initialize = []{\n    ios::sync_with_stdio(false); cin.tie(nullptr);\n    return nullptr;\n}();\nclass Solution {\npublic:\n    vector<int> maximumBeauty(vector<vector<int>>& it, vector<int>& q) {\n        int n=it.size();\n        int m=q.size();\n        sort(it.begin(),it.end());\n        map<int,int>mp;\n        mp[0]=0;\n        mp[it[0][0]]=it[0][1];\n        int ma=0;\n        for(int i=1;i<n;i++){\n            it[i][1]=it[i][1]>it[i-1][1]?it[i][1]:it[i-1][1];\n            mp[it[i][0]]=it[i][1];\n        }\n        vector<int>ans;\n        for(int i=0;i<m;i++){\n            if(!mp.count(q[i])){\n                mp[q[i]]=0;\n            }\n        }\n        for(auto it=mp.begin();it!=mp.end();it++){\n            auto it1=it;\n            it1--;\n            if(it->second==0){\n                it->second=it1->second;\n            }\n        }\n        for(auto x:q){\n            ans.push_back(mp[x]);\n        }\n        return ans;\n    }\n};\n```\n\nIf u Like the Solution Please Do Upvote
['Sorting']