Answer to Question #229608 in C++ for Azimjon Fayzulloev

Question #229608

Algorithmic Problem

You are given the arrival and leaving times of n customers in a restaurant.

What was the maximum number of customers?

Input

The first input line has an integer n: the number of customers.

After this, there are n lines that describe the customers. Each line has two integers a and b: the arrival and leaving times of a customer.

You may assume that all arrival and leaving times are distinct.

Output

Print one integer: the maximum number of customers.

Example

Input:

3

5 8

2 4

3 9

Output:

2



1
Expert's answer
2021-08-25T18:25:56-0400
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{  
   int n;
   int a,b;
   int mxa=-100000;
   int mxb=mxa;
   int cnt=0;
   cin>>n;
   for(int i=0;i<n;i++)
   {
       cin>>a>>b;
       if(a>mxa || b>mxb)
       {
           cnt++;
           if(a>mxa)
           mxa=a;
           if(b>mxb)
           mxb=b;
       }
   }
   cout<<cnt;
   return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS