You are viewing a single comment's thread. Return to all comments →
C# .NET Solution:
static long minTime(long[] machines, long goal) { Array.Sort(machines); long maximumPossibleTime = machines.Last() * goal / machines.Length; long minimumPossibleTime = machines.First() * goal / machines.Length; long numberOfDays = BinarySearchForOptimalTime(machines, goal, minimumPossibleTime, maximumPossibleTime); return numberOfDays; } static long BinarySearchForOptimalTime(long[] machines, long goal, long min, long max) { long mid = 0, noOfItems; while(min<max) { mid = min + (max - min) / 2; noOfItems = CalculateItemsForGivenDays(machines, mid); if(noOfItems < goal) min = mid + 1; else max = mid; } return max; } static long CalculateItemsForGivenDays(long[] machines, long days) { long items = 0; for(int i=0; i<machines.Length; i++) items += (days/machines[i]); return items; }
Minimum Time Required
You are viewing a single comment's thread. Return to all comments →
C# .NET Solution: