3
int latestTimeCatchTheBus(vector<int> &buses, vector<int> &passengers, int capacity) {5
sort(buses.begin(), buses.end());6
sort(passengers.begin(), passengers.end());8
int m = passengers.size();10
for (auto p : passengers) {15
for (int i = 0; i < n; i++) {16
int currbus = buses[i]; // curr bus depature time.17
int count = 0; // number of people in curr bus20
while (!q.empty() && count < capacity && q.front() <= currbus) {23
if (st.find(x - 1) == st.end()) // checking if person timing-1 doesnt24
// exist and update the answer.29
if (count < capacity) {30
while (st.find(currbus) != st.end()) // starting from dept time find a time which does not31
// exist int the set already.35
ans = max(ans, currbus);