Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- int m = in.nextInt();
- int[][] arr = new int[n][m];
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- arr[i][j] = in.nextInt();
- }
- }
- ArrayList minsX;
- ArrayList minsY;
- ArrayList gMinsX = new ArrayList();
- ArrayList gMinsY = new ArrayList();
- for (int j = 0; j < n; j++) {
- minsX = new ArrayList();
- minsY = new ArrayList();
- int min = 1000000;
- for (int i = 0; i < m; i++) {
- if (arr[j][i] == min) {
- minsX.add(j);
- minsY.add(i);
- }
- if (arr[j][i] < min) {
- min = arr[j][i];
- minsX = new ArrayList();
- minsY = new ArrayList();
- minsX.add(j);
- minsY.add(i);
- }
- }
- gMinsX.addAll(minsX);
- gMinsY.addAll(minsY);
- }
- ArrayList maxsX;
- ArrayList maxsY;
- ArrayList gMaxsX = new ArrayList();
- ArrayList gMaxsY = new ArrayList();
- for (int i = 0; i < m; i++) {
- maxsX = new ArrayList();
- maxsY = new ArrayList();
- int max = -1;
- for (int j = 0; j < n; j++) {
- if (arr[j][i] == max) {
- maxsX.add(j);
- maxsY.add(i);
- }
- if (arr[j][i] > max) {
- max = arr[j][i];
- maxsX = new ArrayList();
- maxsY = new ArrayList();
- maxsX.add(j);
- maxsY.add(i);
- }
- }
- gMaxsX.addAll(maxsX);
- gMaxsY.addAll(maxsY);
- }
- int counter = 0;
- for (int i = 0, li = gMinsX.size(); i < li; i++) {
- for (int j = 0, lj = gMaxsX.size(); j < lj; j++) {
- if (gMinsX.get(i) == gMaxsX.get(j) &&
- gMinsY.get(i) == gMaxsY.get(j)) counter += 1;
- }
- }
- System.out.println(counter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment