Check if it is possible to make two matrices strictly increasing by swapping corresponding values only | C # implementation of the above approach ; Function to check whether the matrices can be made strictly increasing with the given operation ; Swap only when a [ i ] [ j ] > b [ i ] [ j ] ; Check if rows are strictly increasing ; Check if columns are strictly increasing ; Driver Code
using System ; using System . Collections ; class GfG { static string Check ( int [ , ] a , int [ , ] b , int n , int m ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) if ( a [ i , j ] > b [ i , j ] ) { int tmp = a [ i , j ] ; a [ i , j ] = b [ i , j ] ; b [ i , j ] = tmp ; } for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m - 1 ; j ++ ) if ( a [ i , j ] >= a [ i , j + 1 ] b [ i , j ] >= b [ i , j + 1 ] ) return " No " ; for ( int i = 0 ; i < n - 1 ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) if ( a [ i , j ] >= a [ i + 1 , j ] b [ i , j ] >= b [ i + 1 , j ] ) return " No " ; return " Yes " ; } public static void Main ( string [ ] arg ) { int n = 2 , m = 2 ; int [ , ] a = { { 2 , 10 } , { 11 , 5 } } ; int [ , ] b = { { 9 , 4 } , { 3 , 12 } } ; Console . Write ( Check ( a , b , n , m ) ) ; } }