-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathremoveAdjacent.cpp
More file actions
47 lines (41 loc) · 861 Bytes
/
removeAdjacent.cpp
File metadata and controls
47 lines (41 loc) · 861 Bytes
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
#include<iostream>
#include<algorithm>
using namespace std;
void findMaxGuests(int arrl[], int exit[], int n)
{
sort(arrl, arrl+n);
sort(exit, exit+n);
int guests_in = 1, max_guests = 1, time = arrl[0];
int i = 1, j = 0;
while (i < n && j < n)
{
// If next event in sorted order is arrival,
// increment count of guests
if (arrl[i] <= exit[j])
{
guests_in++;
// Update max_guests if needed
if (guests_in > max_guests)
{
max_guests = guests_in;
time = arrl[i];
}
i++; //increment index of arrival array
}
else // If event is exit, decrement count
{ // of guests.
guests_in--;
j++;
}
}
cout << "Maximum Number of Guests = " << max_guests
<< " at time " << time;
}
int main()
{
int arrl[] = {1, 2, 10, 5, 5};
int exit[] = {4, 5, 12, 9, 12};
int n = sizeof(arrl)/sizeof(arrl[0]);
findMaxGuests(arrl, exit, n);
return 0;
}