Maximum value in an array after m range increment operations | Python3 progrma of simple approach to find maximum value after m range increments . ; Function to find the maximum element after m operations ; Start performing m operations ; Store lower and upper index i . e . range ; Add ' k [ i ] ' value at this operation to whole range ; Find maximum value after all operations and return ; Driver code ; Number of values ; Value of k to be added at each operation
import sys NEW_LINE def findMax ( n , a , b , k , m ) : NEW_LINE INDENT arr = [ 0 ] * n NEW_LINE for i in range ( m ) : NEW_LINE INDENT lowerbound = a [ i ] NEW_LINE upperbound = b [ i ] NEW_LINE for j in range ( lowerbound , upperbound + 1 ) : NEW_LINE arr [ j ] += k [ i ] NEW_LINE res = - sys . maxsize - 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT res = max ( res , arr [ i ] ) NEW_LINE return res NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 5 NEW_LINE a = [ 0 , 1 , 2 ] NEW_LINE b = [ 1 , 4 , 3 ] NEW_LINE k = [ 100 , 100 , 100 ] NEW_LINE m = len ( a ) NEW_LINE print ( " Maximum ▁ value ▁ after ▁ ' m ' ▁ operations ▁ is ▁ " , findMax ( n , a , b , k , m ) ) NEW_LINE DEDENT