Geek wants to scan N documents using two scanners. If S1 and S2 are the time taken by the scanner 1 and scanner 2 to scan a single document, find the minimum time required to scan all the N documents.
Time : O(log(min(t1, t2) * n))
Space : O(1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
classSolution{ public: intminTime(int t1, int t2, int N){ int l = 0, r = min(t1, t2) * N, res = INT_MAX; while(l <= r) { int m = l + (r - l) / 2; int scan = m / t1 + m / t2; if(scan >= N) res = min(res, m); if(scan >= N) r = m - 1; else l = m + 1; } return res; }