scala dp
```scala []
object Solution {
  def maximumAmount(coins: Array[Array[Int]]): Int = {
    val dp = Array.fill(coins.size,coins.head.size,4)(-250_000_001)
    dp(0)(0)(0) = coins(0)(0); dp(0)(0)(1) = coins(0)(0) max 0
    for{
      k <- (0 to 2).iterator
      i <- coins.indices.iterator
      j <- coins.head.indices.iterator
    } {
      if(i>0) dp(i)(j)(k) = (dp(i-1)(j)(k)+coins(i)(j)) max  dp(i)(j)(k)
      if(j>0) dp(i)(j)(k) = (dp(i)(j-1)(k)+coins(i)(j)) max  dp(i)(j)(k)
      if(coins(i)(j)<0 && k<2) {
        if(i>0) dp(i)(j)(k+1) = (dp(i-1)(j)(k)) max  dp(i)(j)(k+1)
        if(j>0) dp(i)(j)(k+1) = (dp(i)(j-1)(k)) max  dp(i)(j)(k+1)
      }
    }
    (0 to 2).map(dp(coins.size-1)(coins.head.size-1)).max
  }
}
```
['Dynamic Programming', 'Matrix', 'Scala']