Created
April 3, 2020 16:11
-
-
Save belushkin/2a92dc8b47d86d1062067beae8a0573f to your computer and use it in GitHub Desktop.
Dreamoon and Ranking Collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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