human
Number of days after which tank will become empty | Utility method to get sum of first n numbers.
Method returns minimum number of days after which tank will become empty.
if water filling is more than capacity then after C days only tank will become empty.
initialize binary search variable.
loop until low is less than high.
if cumulate sum is greater than ( C - l ) then search on left side.
if ( C - l ) is more then search on right side.
Final answer will be obtained by adding l to binary search result.
Driver code"
Solution in Python:
 ... What is a code to number of days after which tank will become empty and the other steps required?
assistant
#Here is code to number of days after which tank will become empty and the other steps required.
 def getCumulateSum ( n ) :
	return int ( ( n * ( n + 1 ) ) / 2 )
def minDaysToEmpty ( C , l ) :
	if ( C <= l ) : return C
	lo , hi = 0 , 1e4
	while ( lo < hi ) :
		mid = int ( ( lo + hi ) / 2 )
		if ( getCumulateSum ( mid ) >= ( C - l ) ) :
			hi = mid
		else :
			lo = mid + 1
	return ( l + lo )
C , l = 5 , 2
print ( minDaysToEmpty ( C , l ) )