Fork Copy #include using namespace std; void oneTest(int tc); void readInput(int &n, int &m, int **&a); void resetArray(int *&a, int length, int start = 0, int value = 0); void printOutput(int tc, int result); int main() { //freopen("input.txt", "r", stdin); int t; cin >> t; for (int test_case = 1; test_case <= t; test_case++) { oneTest(test_case); } } void oneTest(int tc) { int m, n; int **a; readInput(m, n, a); int *maxH = new int[m]; int *maxC = new int[n]; resetArray(maxH, m); resetArray(maxC, n); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (a[i][j] > maxH[i]) { maxH[i] = a[i][j]; } if (a[i][j] > maxC[j]) { maxC[j] = a[i][j]; } } } int result = m * n; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (a[i][j] < maxH[i] || a[i][j] < maxC[j]) { result--; } } } printOutput(tc, result); } void readInput(int &m, int &n, int **&a) { cin >> m >> n; a = new int*[m]; for (int i = 0; i < m; i++) { a[i] = new int[n]; } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } } void resetArray(int *&a, int length, int start, int value) { for (int i = start; i < length; i++) { a[i] = value; } } void printOutput(int tc, int result) { cout << "#" << tc << " " << result << endl; }