Skip to content

Commit 7e066b3

Browse files
committed
2323 solved.
1 parent 148e827 commit 7e066b3

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
project(cpp_2323)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
add_executable(cpp_2323 main.cpp)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/// Source : https://leetcode.com/problems/find-minimum-time-to-finish-all-jobs-ii/
2+
/// Author : liuyubobobo
3+
/// Time : 2022-06-30
4+
5+
#include <iostream>
6+
#include <vector>
7+
#include <algorithm>
8+
9+
using namespace std;
10+
11+
12+
/// Binary Search
13+
/// Time Complexity: O(nlogn + nlog(max_jobs))
14+
/// Space Complexity: O(1)
15+
class Solution {
16+
public:
17+
int minimumTime(vector<int>& jobs, vector<int>& workers) {
18+
19+
sort(jobs.begin(), jobs.end());
20+
sort(workers.begin(), workers.end());
21+
22+
int l = 1, r = 1e5;
23+
while(l < r){
24+
int mid = (l + r) / 2;
25+
if(ok(jobs, workers, mid)) r = mid;
26+
else l = mid + 1;
27+
}
28+
return l;
29+
}
30+
31+
private:
32+
bool ok(const vector<int>& jobs, const vector<int>& workers, int d){
33+
34+
for(int i = 0; i < workers.size(); i ++)
35+
if(1ll * workers[i] * d < 1ll * jobs[i]) return false;
36+
return true;
37+
}
38+
};
39+
40+
41+
int main() {
42+
43+
vector<int> jobs1 = {5, 2, 4}, workers1 = {1, 7, 5};
44+
cout << Solution().minimumTime(jobs1, workers1) << '\n';
45+
// 2
46+
47+
return 0;
48+
}

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,7 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
21692169
| 2320 | [Count Number of Ways to Place Houses](https://leetcode.com/problems/count-number-of-ways-to-place-houses/) | [] | [C++](2001-2500/2320-Count-Number-of-Ways-to-Place-Houses/cpp-2320/) | | |
21702170
| 2321 | [Maximum Score Of Spliced Array](https://leetcode.com/problems/maximum-score-of-spliced-array/) | [] | [C++](2001-2500/2321-Maximum-Score-Of-Spliced-Array/cpp-2321/) | | |
21712171
| 2322 | [Minimum Score After Removals on a Tree](https://leetcode.com/problems/minimum-score-after-removals-on-a-tree/) | [] | [C++](2001-2500/2322-Minimum-Score-After-Removals-on-a-Tree/cpp-2322/) | | |
2172+
| 2323 | [Find Minimum Time to Finish All Jobs II](https://leetcode.com/problems/find-minimum-time-to-finish-all-jobs-ii/) | [] | [C++](2001-2500/2323-Find-Minimum-Time-to-Finish-All-Jobs-II/cpp-2323/) | | |
21722173
| | | | | | |
21732174

21742175
## 力扣中文站比赛

0 commit comments

Comments
 (0)