2054.cpp (651B)
1 class Solution { 2 public: 3 int maxTwoEvents(const vector<vector<int>> &events) const { 4 using type_t = tuple<int, int, int>; 5 vector<type_t> times; 6 7 times.reserve(2 * size(events)); 8 for (const auto &e : events) { 9 times.emplace_back(e[0], 1, e[2]); 10 times.emplace_back(e[1] + 1, 0, e[2]); 11 } 12 13 sort(begin(times), end(times)); 14 15 int res = 0, maxi = 0; 16 for (const auto [time, is_start, val] : times) { 17 if (is_start) 18 res = max(res, val + maxi); 19 else 20 maxi = max(maxi, val); 21 } 22 23 return res; 24 } 25 };