Easy Binary Search Solution
IntuitionI use binary search on time (val) because the more time we allow, the more cars can be repaired. The valid function checks if a given time val is suffi
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
I use **binary search** on time (`val`) because the more time we allow, the more cars can be repaired. The `valid` function checks if a given time `val` is sufficient by calculating how many cars can be repaired using the given `ranks`. 

# Approach
<!-- Describe your approach to solving the problem. -->
We perform **binary search** on the minimum time required (`val`) in the range `[0, max_rank * cars^2]`. For each `mid`, we check if the total cars can be repaired using a **greedy approach** by summing up `sqrt(mid / rank[i])` for each mechanic. 

# Complexity
- Time complexity:O(n log (max_rank * cars²))
<!-- 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:
    bool valid(const vector<int>& ranks, int cars, long long val) {
        for (int i = 0; i < ranks.size(); i++) {
            long long curr = (long long)sqrt(val / ranks[i]);
            cars -= curr;
            if (cars <= 0)
                return true;
        }
        return false;
    }

    long long repairCars(vector<int>& ranks, int cars) {
        long long low = 0;
        long long high =
            (long long)*max_element(ranks.begin(), ranks.end()) * cars * cars;
        long long ans = high;

        while (low <= high) {
            long long mid = (low + high)/2;
            if (valid(ranks, cars, mid)) {
                ans = mid;
                high = mid - 1;
            } 
            else {
                low = mid + 1;
            }
        }
        return ans;
    }
};

```
['Binary Search', 'C++']