python O(NlogN) solution, DP, binary search is not used
\nclass Solution:\n    def maxEnvelopes(self, envelopes: List[List[int]]) -> int:\n        # sort the width by ascending order, the height by descending order\n
```\nclass Solution:\n    def maxEnvelopes(self, envelopes: List[List[int]]) -> int:\n        # sort the width by ascending order, the height by descending order\n        envelopes.sort(key=lambda x: (x[0], -x[1]))\n        tops = []\n        for e in envelopes:\n            if tops and tops[-1][0] < e[0] and tops[-1][1] < e[1]: \n                # To speed up, if height and width is bigger than the envelope in our piles, create a new pile\n                tops.append(e)\n                continue\n\n            for i in range(len(tops)):\n                if tops[i][1] >= e[1]: \n                    # if envelope is smaller than top envelope of pile, update top envelope of pile\n                    tops[i] = e\n                    break\n            else:\n                # not trigger break (height and width is bigger than the envelope in our piles, create a new pile)\n                tops.append(e)\n        return len(tops)\n```
['Dynamic Programming', 'Python']