-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice.cpp
54 lines (49 loc) · 1.27 KB
/
practice.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
#include<bits/stdc++.h>
using namespace std;
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());
for(int i=0;i<meetings.size();i++){
int start = meetings[i][0], end = meetings[i][1];
bool flag = false;
int minind = -1;
long long val = 1e18;
for(int j=0;j<n;j++){
if(times[j]<val) val = times[j], minind = j;
if(times[j] <= start){
flag = true;
ans[j]++;
times[j] = end;
break;
}
}
if(!flag){
ans[minind]++;
times[minind]+=(1ll*(end-start));
}
}
int maxi = -1, id = -1;
for(int i =0;i<n;i++){
if(ans[i]>maxi) maxi = ans[i], id = i;
}
return id;
}
};
signed main()
{
int n;
cin>>n;
vector<vector<int>>nums(n,vector<int>(2,-1));
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
cin>>nums[i][j];
}
}
Solution ob;
auto ans = ob.mostBooked(n,nums);
cout<<ans;
return 0;
}