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 { #include <bits/stdc++.h> NEW_LINE using namespace std ; string Check ( int a [ ] [ 2 ] , int b [ ] [ 2 ] , 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 ] ) swap ( a [ i ] [ j ] , b [ i ] [ j ] ) ; 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 " ; } int main ( ) { int n = 2 , m = 2 ; int a [ ] [ 2 ] = { { 2 , 10 } , { 11 , 5 } } ; int b [ ] [ 2 ] = { { 9 , 4 } , { 3 , 12 } } ; cout << ( Check ( a , b , n , m ) ) ; }