Skip to content

Commit c29a9b8

Browse files
authored
Create 3439. Reschedule Meetings for Maximum Free Time I (#836)
2 parents 8277ed8 + 60ce607 commit c29a9b8

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Solution {
2+
public:
3+
int maxFreeTime(int eventt, int k, vector<int>& strtt, vector<int>& endt) {
4+
int n = strtt.size();
5+
vector<int> gaps(n+1, 0);
6+
7+
gaps[0] = strtt[0];
8+
for(int i=1; i<n; i++){
9+
gaps[i] = strtt[i] - endt[i-1];
10+
}
11+
gaps[n] = eventt - endt[n-1];
12+
13+
for(int ele:gaps) cout<<ele<<" ";
14+
15+
int tmp = 0;
16+
int j=0;
17+
while(j<=k){
18+
tmp += gaps[j];
19+
j++;
20+
}
21+
22+
int ans = tmp;
23+
int i=0;
24+
while(j<=n && i<=n){
25+
tmp -= gaps[i];
26+
i++;
27+
tmp += gaps[j];
28+
j++;
29+
ans = max(ans, tmp);
30+
}
31+
32+
return ans;
33+
34+
}
35+
};

0 commit comments

Comments
 (0)