1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution { public: bool carPooling(vector<vector<int>>& trips, int capacity) { map<int, int> m; for (const auto &t : trips) { m[t[1]] += t[0]; m[t[2]] -= t[0]; } int cnt = 0; for (const auto &[k, v] : m) { cnt += v; if (cnt > capacity) return false; } return true; } };
|