C++ Time O(NlogN) Space O(N) , similar to LIS nlogn solution
bool cmp (pair<int, int> i, pair<int, int> j) {\n        if (i.first == j.first)\n            return i.second > j.second;\n        return i.first < j.first;\n  
    bool cmp (pair<int, int> i, pair<int, int> j) {\n        if (i.first == j.first)\n            return i.second > j.second;\n        return i.first < j.first;\n    }\n    \n    class Solution {\n    public:\n        int maxEnvelopes(vector<pair<int, int>>& envelopes) {\n            int N = envelopes.size();\n            vector<int> candidates;\n            sort(envelopes.begin(), envelopes.end(), cmp);\n            for (int i = 0; i < N; i++) {\n                int lo = 0, hi = candidates.size() - 1;\n                while (lo <= hi) {\n                    int mid = lo + (hi - lo)/2;\n                    if (envelopes[i].second > envelopes[candidates[mid]].second)\n                        lo = mid + 1;\n                    else\n                        hi = mid - 1;\n                }\n                if (lo == candidates.size())\n                    candidates.push_back(i);\n                else\n                    candidates[lo] = i;\n            }\n            return candidates.size();\n        }\n    };
[]