-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHOTEL.cpp
51 lines (41 loc) · 957 Bytes
/
HOTEL.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
44
45
46
47
48
49
50
51
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<pair<int,int>> v(n);
//taking input of arrival time
for(int i=0;i<n;i++)
cin>>v[i].first;
//taking input of leaving time
for(int i=0;i<n;i++)
cin>>v[i].second;
//marking in ans array
vector<int> ans(1001,0);
for(int i=0;i<v.size();i++)
{
for(int j=v[i].first;j<v[i].second;j++)
ans[j]++;
}
int maxi=0;
for(int i=0;i<ans.size();i++)
{
maxi=max(maxi,ans[i]);
}
cout<<maxi<<endl;
}
return 0;
}
/*
time complexity - O(n)-> taking input
O(n)-> taking input
O(1000*n) -> marking in ans array
overall time complexity is O(1000*n)
which can be n^2 if limit n instead of 1000
*/