// Russian Doll Envelopes class Solution { public: int maxEnvelopes(vector>& a) { sort(a.begin(), a.end(), [](const pair& x, const pair& y) { return x.first != y.first ? x.first < y.first : x.second > y.second; }); vector b; for (auto& x: a) { auto t = lower_bound(b.begin(), b.end(), x.second); if (b.end() == t) b.push_back(x.second); else *t = x.second; } return b.size(); } };