Easy C++ solution DP+binary search approach Beat 99.61%✅✅
\n\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) O(nlogn)\n\n- Space complexity:\n Add your space complexity here, e.g. O(n) O(n)
\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(nlogn)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->O(n)\n\n# Code\n```\nclass Solution {\npublic:\n    static bool compare(vector<int>& a, vector<int>& b){\n        if(a[0]==b[0])\n            return a[1]>b[1];\n        return a[0]<b[0];\n    }\n    int mostOptimal(vector<vector<int>>& envelopes){\n       \n        vector<int> ans;\n        ans.push_back(envelopes[0][1]);\n        for(int i=1;i<envelopes.size();i++){\n            if(envelopes[i][1]>ans.back())\n                ans.push_back(envelopes[i][1]);\n            else{\n                int index=lower_bound(ans.begin(),ans.end(),envelopes[i][1])-ans.begin();\n                ans[index]=envelopes[i][1];\n            }\n        }\n        return ans.size();\n    }\n    int maxEnvelopes(vector<vector<int>>& envelopes) {\n        \n        sort(envelopes.begin(),envelopes.end(),compare);\n        int prev=-1;\n        int curr=0;\n        return mostOptimal(envelopes);\n\n         \n    }\n};\n```
['C++']