-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestaurantCustomers.cpp
More file actions
61 lines (47 loc) · 1.06 KB
/
RestaurantCustomers.cpp
File metadata and controls
61 lines (47 loc) · 1.06 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
58
59
60
61
#include <bits/stdc++.h>
using namespace std;
typedef long long l1;
void swap(int*a,int*b){
int temp = *a;
*a = *b;
*b = temp;
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
if(a.first == b.first)
return a.second < b.second;
else
return a.first < b.first;
}
int gcd(int a,int b){
if(a > b)return gcd(b,a);
while(b%a){
a = b%a;
}
return a;
}
int main(){
int n;
cin >> n;
int array1[n];
int array2[n];
for(int i = 0 ; i < n ; i ++){
cin >> array1[i];
cin >> array2[i];
}
sort(array1,array1+n);
sort(array2,array2+n);
int maxi = 0;
int curr = 0;
int max_time = 0;
int curr_time = 1;
int i = 0;
int j = 0;
while(curr_time <= array2[n-1]){
if(array1[j] == curr_time){curr++;j++;}
else if(array2[i] == curr_time){if(maxi < curr){maxi = curr;max_time = curr_time;};curr--,i++;}
else{curr_time = (array1[j] < array2[i] ? array1[j] : array2[i]);}
}
cout << maxi;
return 0;
}