-
Notifications
You must be signed in to change notification settings - Fork 0
/
N meetings in one room.cpp
75 lines (62 loc) · 1.73 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
PROBLEM:
There is one meeting room in a firm. There are N meetings in the form of (S[i], F[i]) where S[i] is start time of meeting i and F[i] is finish time of meeting i.
What is the maximum number of meetings that can be accommodated in the meeting room?
Input:
The first line of input consists number of the test cases. The description of T test cases is as follows:
The first line consists of the size of the array, second line has the array containing the starting time of all the meetings each separated by a space, i.e., S [ i ].
And the third line has the array containing the finishing time of all the meetings each separated by a space, i.e., F [ i ].
Output:
In each separate line print the order in which the meetings take place separated by a space.
Constraints:
1 ≤ T ≤ 70
1 ≤ N ≤ 100
1 ≤ S[ i ], F[ i ] ≤ 100000
Example:
Input:
2
6
1 3 0 5 8 5
2 4 6 7 9 9
8
75250 50074 43659 8931 11273 27545 50879 77924
112960 114515 81825 93424 54316 35533 73383 160252
Output:
1 2 4 5
6 7 1
SOLUTION:
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int n,i,last;
cin>>n;
vector<pair<int,int>> v(n);
unordered_map<int,int> m;
vector<int> s;
for(i=0;i<n;i++)
cin>>v[i].second;
for(i=0;i<n;i++)
{
cin>>v[i].first;
m[v[i].first+v[i].second]=i+1;
}
sort(v.begin(),v.end());
s.push_back(m[v[0].first+v[0].second]);
last=v[0].first;
for(i=0;i<n-1;i++)
{
if(v[i+1].second>last)
{
s.push_back(m[v[i+1].first+v[i+1].second]);
last=v[i+1].first;
}
}
for(auto i:s)
cout<<i<<" ";
cout<<endl;
}
return 0;
}