-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy path2402. Meeting Rooms III
42 lines (41 loc) · 1.15 KB
/
2402. Meeting Rooms III
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
class Solution {
public:
int mostBooked(int n, vector<vector<int>>& meetings) {
int len=size(meetings);
vector<long long>endtime(n,0);
vector<int>count(n,0);
sort(begin(meetings),end(meetings));
for(int i=0;i<len;i++){
int start=meetings[i][0];
int time=meetings[i][1]-start;
bool isdelay = true;
long long mindelay=LLONG_MAX;
int indx;
for(int j=0;j<n;j++){
if(endtime[j]<=start){
endtime[j]=meetings[i][1];
count[j]++;
isdelay = false;
break;
}else{
if(endtime[j]<mindelay){
mindelay=endtime[j];
indx=j;
}
}
}
if(isdelay){
endtime[indx]+=time;
count[indx]++;
}
}
int ans=0;
for(int i=0;i<n;i++){
cout<<count[i]<<" ";
if(count[i]>count[ans]){
ans =i;
}
}
return ans;
}
};