🔥100% Simple & Easy solution! ✅| 🎯Beats 93.97% |🚀 Binary Search | O(N log M) | C++
IntuitionWe need to find the minimum time required to repair all cars given different ranks of mechanics. The repair time for a mechanic with rank r follows the
## Intuition
We need to find the minimum time required to repair all `cars` given different `ranks` of mechanics. The repair time for a mechanic with rank `r` follows the formula `t = r * (c^2)`, where `c` is the number of cars they repair. Since time is a continuous quantity, we can use **Binary Search on Answer** to efficiently determine the minimum possible time.

---

## Approach
1. **Binary Search on Time (`mid`)**  
   - The lower bound `low` starts at `1`, and the upper bound `high` is set to a large value (`1e14`).
   - Perform binary search in this range to find the smallest possible time that allows repairing all `cars`.

2. **Checking Feasibility (`solve` function)**  
   - For each mechanic rank, calculate how many cars they can repair in `mid` time using `c = sqrt(mid / rank)`.  
   - Sum up all the cars repaired.
   - If the total number of repaired cars is at least `cars`, return `true` (valid `mid`).

3. **Binary Search Execution**  
   - Compute `mid = (low + high) / 2`.
   - If `solve` returns `true`, update `ans = mid` and search for a smaller `mid` (`high = mid - 1`).
   - Otherwise, search on the right side (`low = mid + 1`).

---

## Complexity
- **Time Complexity:**  
  - **O(n log T)** where `n` is the number of mechanics and `T` is `1e14`. The binary search runs in **O(log T)**, and `solve` runs in **O(n)**.

- **Space Complexity:**  
  - **O(1)**, as we use only a few extra variables.

---

## Code
```cpp
class Solution {
public:
    bool solve(vector<int>& ranks, int cars, long long mid) {
        long long count = 0;
        for (auto it : ranks) {
            long long c = sqrt(mid / it);
            count += c;
            if (count >= cars) return true;
        }
        return count >= cars;
    }
    
    long long repairCars(vector<int>& ranks, int cars) {
        long long low = 1, high = 1e14;
        long long ans = 0;
        while (low <= high) {
            long long mid = (low + high) / 2;
            if (solve(ranks, cars, mid)) {
                ans = mid;
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        return ans;
    }
};
```

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