Update answer for both rows
for ( int i = 0 ; i < 2 ; i ++ ) { if ( i == 1 ) { dp [ i , j ] = Math . Max ( arr [ i , j ] + dp [ 0 , j + 1 ] , arr [ i , j ] + dp [ 0 , j + 2 ] ) ; } else { dp [ i , j ] = Math . Max ( arr [ i , j ] + dp [ 1 , j + 1 ] , arr [ i , j ] + dp [ 1 , j + 2 ] ) ; } } }