C++✅✅| Simplest approach🚀🚀
Complexity
Time complexity: O(nlogn)

Space complexity: O(1)
Code


# Complexity
- Time complexity: O(nlogn)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    long long repairCars(vector<int>& ranks, int cars) {
        auto check = [&](long long mid) {
            long long cnt = 0;
            for (int r : ranks) {
                cnt += static_cast<long long>(sqrt(mid / r));
                if (cnt >= cars) return true; 
            }
            return false;
        };

        long long min_rank = *min_element(ranks.begin(), ranks.end());
        long long l = 1, h = min_rank * static_cast<long long>(cars) * cars;
        
        while (l < h) {
            long long mid = l + (h - l) / 2;
            if (check(mid)) {
                h = mid;
            } else {
                l = mid + 1;
            }
        }
        return l;
    }
};
```
['Array', 'Binary Search', 'C++']