Maximize number of circular buildings that can be covered by L length wire | Python3 program for the above approach ; Function to find the maximum number of buildings covered ; Store the current sum ; Traverse the array ; Add the length of wire required for current building to cur_sum ; Add extra unit distance 1 ; If curr_sum <= length of wire increment count by 1 ; If curr_sum > length of wire increment start by 1 and decrement count by 1 and update the new curr_sum ; Update the max_count ; Return the max_count ; Driver Code ; Given Input ; Size of the array ; Function Call
Pi = 3.141592 NEW_LINE def MaxBuildingsCovered ( arr , N , L ) : NEW_LINE INDENT curr_sum = 0 NEW_LINE start = 0 NEW_LINE curr_count = 0 NEW_LINE max_count = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT curr_sum = curr_sum + ( arr [ i ] * Pi ) NEW_LINE if ( i != 0 ) : NEW_LINE INDENT curr_sum += 1 NEW_LINE DEDENT if ( curr_sum <= L ) : NEW_LINE INDENT curr_count += 1 NEW_LINE DEDENT elif ( curr_sum > L ) : NEW_LINE INDENT curr_sum = curr_sum - ( arr [ start ] * Pi ) NEW_LINE curr_sum -= 1 NEW_LINE start += 1 NEW_LINE curr_count -= 1 NEW_LINE DEDENT max_count = max ( curr_count , max_count ) NEW_LINE DEDENT return max_count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 4 , 1 , 6 , 2 ] NEW_LINE L = 24 NEW_LINE N = len ( arr ) NEW_LINE print ( MaxBuildingsCovered ( arr , N , L ) ) NEW_LINE DEDENT