Minimum time required to transport all the boxes from source to the destination under the given constraints | Function that returns true if it is possible to transport all the boxes in the given amount of time ; If all the boxes can be transported in the given time ; If all the boxes can 't be  transported in the given time ; Function to return the minimum time required ; Sort the two arrays ; Stores minimum time in which all the boxes can be transported ; Check for the minimum time in which all the boxes can be transported ; If it is possible to transport all the boxes in mid amount of time ; Driver code
def isPossible ( box , truck , n , m , min_time ) : NEW_LINE INDENT temp = 0 NEW_LINE count = 0 NEW_LINE while ( count < m ) : NEW_LINE INDENT j = 0 NEW_LINE while ( j < min_time and temp < n and truck [ count ] >= box [ temp ] ) : NEW_LINE INDENT temp += 1 NEW_LINE j += 2 NEW_LINE DEDENT count += 1 NEW_LINE DEDENT if ( temp == n ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def minTime ( box , truck , n , m ) : NEW_LINE INDENT box . sort ( ) ; NEW_LINE truck . sort ( ) ; NEW_LINE l = 0 NEW_LINE h = 2 * n NEW_LINE min_time = 0 NEW_LINE while ( l <= h ) : NEW_LINE INDENT mid = ( l + h ) // 2 NEW_LINE if ( isPossible ( box , truck , n , m , mid ) ) : NEW_LINE INDENT min_time = mid NEW_LINE h = mid - 1 NEW_LINE DEDENT else : NEW_LINE INDENT l = mid + 1 NEW_LINE DEDENT DEDENT return min_time NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT box = [ 10 , 2 , 16 , 19 ] NEW_LINE truck = [ 29 , 25 ] NEW_LINE n = len ( box ) NEW_LINE m = len ( truck ) NEW_LINE print ( minTime ( box , truck , n , m ) ) NEW_LINE DEDENT