forked from recongamer/Hacktoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
N-meetings-in-one-room.cpp
43 lines (40 loc) · 963 Bytes
/
N-meetings-in-one-room.cpp
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
/*
There is one meeting room in a firm. There are N meetings in the form of (start[i], end[i]) where start[i] is start time of meeting i and end[i] is finish time of meeting i.
Find the maximum number of meetings that can be accomadated in one room.
*/
/*
Time Complexity : O(N*log(N))
*/
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
int maxMeetings(int start[], int end[], int n)
{
int count=1;
vector<pair<int,int>>v;
for(int i=0;i<n;i++){
v.push_back({end[i],start[i]});
}
sort(v.begin(),v.end());
int temp=v[0].first;
for(int i=1;i<n;i++){
if(v[i].second>temp){
count++;
temp=v[i].first;
}
}
return count;
}
int main()
{
int n;
cin >> n;
int start[n], end[n];
for (int i = 0; i < n; i++)
cin >> start[i];
for (int i = 0; i < n; i++)
cin >> end[i];
cout<<maxMeetings(start, end, n);
return(0);
}