View Code of Problem 85

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<climits>

using namespace std;


int main()
{
	int m, n;
	cin >> m >> n;

	vector<vector<int>> mat(m, vector<int>(n));
	vector<int> row_min(m);

	for (int i = 0; i < m; i++) {

		for (int j = 0; j < n; j++)
			cin >> mat[i][j];
	}

	for (int i = 0; i < m; i++) {

		row_min[i] = mat[i][0];

		for (int j = 1; j < n; j++) {

			if (mat[i][j] < row_min[i])
				row_min[i] = mat[i][j];
		}
	}

	vector<pair<int, int>> res;

	for (int j = 0; j < n; j++) {

		pair<int, int> max_num = make_pair(mat[0][j], 0);

		for (int i = 1; i < m; i++) {

			if(mat[i][j] > max_num.first)
				max_num = make_pair(mat[i][j], i);
		}

		if (max_num.first == row_min[max_num.second])
			res.push_back({ max_num.second, j });
	}

	for (int i = 0; i < res.size(); i++)
		cout << res[i].first + 1 << " " << res[i].second + 1 << endl;

}

Double click to view unformatted code.


Back to problem 85