Skip to content

Instantly share code, notes, and snippets.

@belushkin
Created April 3, 2020 16:11
Show Gist options
  • Save belushkin/2a92dc8b47d86d1062067beae8a0573f to your computer and use it in GitHub Desktop.
Save belushkin/2a92dc8b47d86d1062067beae8a0573f to your computer and use it in GitHub Desktop.
Dreamoon and Ranking Collection
import java.util.Arrays;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int p = Integer.parseInt(sc.nextLine());
for (int i = 0; i < p; i++) {
String s = sc.nextLine();
String[] result = s.split(" ");
int n = Integer.parseInt(result[0]);
int x = Integer.parseInt(result[1]);
s = sc.nextLine();
result = s.split(" ");
int[] integers = new int[result.length];
for (int j = 0; j < integers.length; j++){
integers[j] = Integer.parseInt(result[j]);
}
integers= java.util.stream.IntStream.of(integers).distinct().toArray();
Arrays. sort(integers);
int res = x;
for (int integer : integers) {
if (integer <= res || integer == res + 1) {
res++;
}
}
System.out.println(res);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment