forked from namishkhanna/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaximumCustomer.cpp
More file actions
57 lines (48 loc) · 1.35 KB
/
maximumCustomer.cpp
File metadata and controls
57 lines (48 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include<map>
#include<algorithm>
using namespace std;
#define OJ \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
int main()
{
OJ;
FIO;
long long int n;
cin >> n;
long long int* arrival = new long long int[n];
long long int* departure = new long long int[n];
for(long long int i=0; i<n; i++){
cin >> arrival[i] >> departure[i];
}
sort(arrival, arrival+n);
sort(departure, departure+n);
for(long long int i=0; i<n; i++){
cout << arrival[i] << " " << departure[i] << endl;
}
cout << endl;
long long int count = 0;
long long int maxCount = 0;
long long int i=0, j=0;
while(i<n && j<n){
if(arrival[i]<departure[j]){
count++;
i++;
} else {
count-=1; //Ek insaan chala gya, kyuki arrival departure se jada ho gya
//For eg, 33 > 21, this means, 21 wle insaan ke phle phle 2 log aye,
// fir jab teesra aya 33 pr, tb tk 21 wala laut gya, islie count-=1
j++;
}
if(maxCount < count){
maxCount = count;
}
}
cout << maxCount << endl;
return 0;
}