Maximize array sum by X increments when each element is divided by 10 | Python3 program for the above problem ; Initialize variables ; Add the current contribution of the element to the answer ; If the value is already maximum then we can 't  change it ; Moves required to move to the next multiple of 10 ; No of times we can add 10 to this value so that its value does not exceed 1000. ; Sort the array ; Adding the values to increase the numbers to the next multiple of 10 ; If the total moves are less than X then increase the answer ; If the moves exceed X then we cannot increase numbers ; If there still remain some moves ; Remaining moves ; Add minimim of increments and remaining / 10 to the answer ; Output the final answer ; Driver Code
def maximizeval10 ( a , n , k ) : NEW_LINE INDENT increments = 0 NEW_LINE ans = 0 NEW_LINE v = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT ans += ( a [ i ] // 10 ) NEW_LINE if ( a [ i ] == 1000 ) : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT v . append ( 10 - a [ i ] % 10 ) NEW_LINE increments += ( 100 - ( ( a [ i ] ) // 10 ) - 1 ) ; NEW_LINE DEDENT DEDENT v . sort ( ) NEW_LINE sum = 0 NEW_LINE for i in range ( len ( v ) ) : NEW_LINE INDENT sum += v [ i ] NEW_LINE if ( sum <= k ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if ( sum < k ) : NEW_LINE INDENT remaining = k - sum NEW_LINE ans += min ( increments , remaining // 10 ) NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 4 NEW_LINE X = 6 NEW_LINE A = [ 4 , 8 , 8 , 8 ] NEW_LINE maximizeval10 ( A , N , X ) NEW_LINE DEDENT