update those rows which lead to maximum score after toggle
update . forEach ( ( value , key ) => { if ( K > 0 ) { var idx = value ; for ( var j = 0 ; j < m ; ++ j ) A [ idx ] [ j ] = ( A [ idx ] [ j ] + 1 ) % 2 ; K -- ; } } ) ;