-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay80.cpp
More file actions
41 lines (41 loc) · 1.12 KB
/
Day80.cpp
File metadata and controls
41 lines (41 loc) · 1.12 KB
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
class Solution {
public:
int mostBooked(int n, vector<vector<int>>& meetings) {
vector<int> ans(n, 0);
vector<long long> times(n, 0);
sort(meetings.begin(), meetings.end());
int m = meetings.size();
for(int i=0;i<m;i++){
int s = meetings[i][0];
int e = meetings[i][1];
bool temp = false;
int minid = -1;
long long val = 1e18;
for(int j=0;j<n;j++){
if(times[j] < val){
val = times[j];
minid = j;
}
if(times[j] <= s){
temp = true;
ans[j]++;
times[j] = e;
break;
}
}
if(!temp){
ans[minid]++;
times[minid] += (1ll*(e-s));
}
}
int maxi = -1;
int id = -1;
for(int i=0;i<n;i++){
if(ans[i] > maxi){
maxi = ans[i];
id = i;
}
}
return id;
}
};