input: Write a python function to optimize an array based on cumulative sums and maximum element.
  assert optimize_array([10, 40, 70, 30, 20]) == [-10, -50, -120, -150, -180]
  assert optimize_array([1, 2, 3, 4, 5]) == [-1, -2, -3, -4, -5]
  assert optimize_array([5, 3, 2, 1, 4]) == [-5, -8, -10, -11, -15]
output: def optimize_array(arr):
      max_elem = max(arr)
      cumulative_sum = 0
      result = []
      for num in arr:
          cumulative_sum += num
          result.append(cumulative_sum - max_elem)
      return result