You are given the arrival and leaving times of n customers in a restaurant.
What was the maximum number of customers in the restaurant at any time?
Input
Each tuple in customers has an arrival time and a leaving time.
You may assume that all arrival and leaving times are distinct.
Output
Print one integer: the maximum number of customers.
def max_customers(customers: List[(int, int)]) -> int:
customers.sort()= []
q
for enter_time, leave_time in customers:
True))
q.append((enter_time, False))
q.append((leave_time,
= 0
customers = 0
max_customers_so_far
for _, status in q:
+= (1 if status else -1)
customers = max(max_customers_so_far, customers)
max_customers_so_far
return max_customers_so_far
#include <functional>
#include <iostream>
#include <queue>
using namespace std;
int main() {
long long n;
long long enter_time;
long long leaving_time;
>> n;
cin
<pair<int, bool>> q;
vector
for (int i = 0; i < n; i++) {
>> enter_time;
cin >> leaving_time;
cin .push_back({enter_time, true});
q.push_back({leaving_time, false});
q}
(q.begin(), q.end());
sort
long long customers = 0;
long long max_customers_so_far = 0;
for (const auto &[l, r] : q) {
if (r == true)
++;
customerselse
--;
customers
= max(max_customers_so_far, customers);
max_customers_so_far }
<< max_customers_so_far;
cout }