public static void main2(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int[] arr = new int[n]; for (int i = 0; i < arr.length; i++) { arr[i] = in.nextInt(); } HashSet<Integer> treePos = new HashSet<>(); for (int i = 1; i <= k; i++) { for (int a : arr) { treePos.add(a); } for (int i1 = 0; i1 < arr.length; i1++) { arr[i1]++; } if (treePos.size()>=k){ System.out.println(i); break; } }
点赞 2

相关推荐

牛客网
牛客企业服务