Advertisement
Guest User

Untitled

a guest
May 24th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.TreeSet;
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.   public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.         int n = sc.nextInt();
  9.         int x = sc.nextInt();
  10.         int k = sc.nextInt();
  11.         TreeSet<Integer> set = new TreeSet<>();
  12.         for (int i = 0; i < n; i++) {
  13.             set.add(sc.nextInt());
  14.         }
  15.         System.out.println(alarm(n, x, k, set));
  16.     }
  17.  
  18.     public static int alarm(int n, int x, int k, TreeSet<Integer> clocks) {
  19.         int result = 0;
  20.         int count = 0;
  21.         while (k > count) {
  22.             count++;
  23.             result = clocks.first();
  24.             clocks.add(clocks.pollFirst() + x);
  25.         }
  26.         return result;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement