-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQue2594.cpp
More file actions
44 lines (35 loc) · 1.22 KB
/
Que2594.cpp
File metadata and controls
44 lines (35 loc) · 1.22 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
42
43
44
// Minimum Time to repair Cars
class Solution {
public:
bool checker(vector<int>& ranks, long long mid, int cars){
int index = 0;
long long countCar = 0;
while(index < ranks.size()){
countCar += sqrt(mid/ranks[index]);
index++;
if (countCar >= cars) return true;
}
// if(countCar >= cars) return true;
// else return false;
return countCar >= cars;
}
long long repairCars(vector<int>& ranks, int cars) {
long long maxEle = *max_element(ranks.begin(),ranks.end());
long long right = maxEle * cars * cars;
// cout<<right<<" ";
long long left = 1;
long long ans = 0;
while(left <= right){
long long mid = left + ((right-left)/2);
// cout<<mid<<endl;
if(checker(ranks,mid,cars)){
ans = mid;
right = mid-1;
}
else{
left = mid+1;
}
}
return ans;
}
};