Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.TreeSet;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int x = sc.nextInt();
- int k = sc.nextInt();
- TreeSet<Integer> set = new TreeSet<>();
- for (int i = 0; i < n; i++) {
- set.add(sc.nextInt());
- }
- System.out.println(alarm(n, x, k, set));
- }
- public static int alarm(int n, int x, int k, TreeSet<Integer> clocks) {
- int result = 0;
- int count = 0;
- while (k > count) {
- count++;
- result = clocks.first();
- clocks.add(clocks.pollFirst() + x);
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement