Apply greedy approach
for i in range ( 0 , int ( n / 2 ) , 1 ) : NEW_LINE INDENT b [ i ] = max ( l , a [ i ] - r ) NEW_LINE b [ n - i - 1 ] = a [ i ] - b [ i ] NEW_LINE l = b [ i ] NEW_LINE r = b [ n - i - 1 ] NEW_LINE DEDENT