Skip to content

Commit 3201f12

Browse files
authored
Create 2594. Minimum Time to Repair Cars (#742)
2 parents 3cddae0 + d462aec commit 3201f12

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

2594. Minimum Time to Repair Cars

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
int freq[101]={0}, minR=101, maxR=0;
4+
inline bool canRepair(int cars, long long t){
5+
long long cnt=0;
6+
for(int x=minR; x<=maxR; x++) {
7+
cnt+=freq[x]*(long long)sqrt(t/x);
8+
if (cnt>=cars) return 1;
9+
}
10+
return cnt>=cars;
11+
}
12+
long long repairCars(vector<int>& ranks, int cars) {
13+
for(int x: ranks){
14+
minR=min(x, minR);
15+
maxR=max(x, maxR);
16+
freq[x]++;
17+
}
18+
long long l=1, r=1LL*minR*cars*cars, m;
19+
20+
while(l<r){
21+
m=(l+r)/2;
22+
if (canRepair(cars, m)) r=m;
23+
else l=m+1;
24+
}
25+
return l;
26+
}
27+
};

0 commit comments

Comments
 (0)