class Solution {
public:
bool carPooling(vector<vector<int>>& trips, int capacity) {
int n = trips.size();
vector<int> count(1001);
for (auto& trip : trips) {
int num = trip[0], from = trip[1], to = trip[2];
count[from] += num;
count[to] -= num;
}
int sum = 0;
for (int element : count) {
sum += element;
if (sum > capacity) return false;
}
return true;
}
};