-
Notifications
You must be signed in to change notification settings - Fork 656
/
Copy pathNmeetingsCpp
37 lines (31 loc) · 836 Bytes
/
NmeetingsCpp
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
struct meeting {
int start;
int end;
int pos;
};
bool comparator(struct meeting m1, meeting m2)
{
if (m1.end < m2.end) return true;
else if(m1.end > m2.end) return false;
else if(m1.pos < m2.pos) return true;
return false;
}
void maxMeetings(int s[], int e[], int n) {
struct meeting meet[n];
for(int i = 0;i<n;i++) {
meet[i].start = s[i], meet[i].end = e[i], meet[i].pos = i+1;
}
sort(meet, meet+n, comparator);
vector<int> answer;
int limit = meet[0].end;
answer.push_back(meet[0].pos);
for(int i = 1;i<n;i++) {
if(meet[i].start > limit) {
limit = meet[i].end;
answer.push_back(meet[i].pos);
}
}
for(int i = 0;i<answer.size();i++) {
cout << answer[i] << " ";
}
}