hwangnk1004 / Algorithm

0 stars 0 forks source link

StepByStep #When Can We Meet? #273

Open hwangnk1004 opened 4 years ago

hwangnk1004 commented 4 years ago

import java.util.Scanner;

public class Main { public static void main(String args[]) {

    Scanner scanner = new Scanner(System.in);

    int n = scanner.nextInt();
    int q = scanner.nextInt();

    int[] arr = new int[101];

    for (int i = 0; i < n; i++) {
        int num = scanner.nextInt();

        for (int j = 0; j < num; j++) {
            arr[scanner.nextInt()]++;
        }
    }

    int x = 0;

    for (int i = 100; i >= 0; i--) {
        if (arr[i] > q && arr[i] <= n) {
            x = Math.max(x,arr[i]);
        }
    }

    if (x == 0) {
        for (int i = 0; i < 100; i++) {
            if (arr[i] == q) {
                x = i;
                break;
            }
        }
        System.out.println(x);
    } else {
        for(int i=0; i<100; i++) {
            if (arr[i] == x) {
                System.out.println(i);
                return;
            }
        }
    }
}

}