scala oneliner
```scala []
object Solution {
  def maximumTotalCost(nums: Array[Int]): Long =
    nums.reverseIterator.foldLeft((0L,0L)){case ((p,n),num) =>
      (num+(p max n), -num+p)
    }._1
}
```
['Greedy', 'Scala']