#include #include using namespace std; int I[100][100]; int c, r; bool view( int a, int b ) { bool temp1 = true; bool temp2 = true; bool temp3 = true; bool temp4 = true; for (int i = a ; i < r ; i++ ) if( I[i][b] > I[a][b] ) { temp1 = false; break; } if(temp1) return true; for (int i = a ; i >= 0 ; i-- ) if( I[i][b] > I[a][b] ) { temp2 = false; break; } if(temp2) return true; for (int j = b ; j>= 0 ; j-- ) if( I[a][j] > I[a][b] ) { temp3 = false; break; } if(temp3) return true; for (int j = b ; j < c ; j++ ) if( I[a][j] > I[a][b] ) { temp4 = false; break; } if(temp4) return true; return false; } int main() { ifstream cin ("problem3.in"); ofstream cout ("problem3.out"); int k; cin >> k; long counter; for( int index = 0 ; index < k ; index++ ) { cin >> r >> c; for( int i = 0 ; i < r ; i++ ) for( int j = 0 ; j < c ; j++ ) cin >> I[i][j]; counter = 0; for( int i = 1 ; i < c-1 ; i++ ) for( int j = 1 ; j < r-1 ; j++) if( !view(i, j) ) counter++; cout << counter; //*********************** if(index != k-1) cout << endl; } cin.close(); cout.close(); return 0; }