fork download
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Ideone {
  5. @SuppressWarnings("unused")
  6. public static void main(String[] args) {
  7. MyScanner in = new MyScanner();
  8.  
  9. int q=in.nextInt();
  10. Main:
  11. while(q-->0) {
  12. int n=in.nextInt(), k=in.nextInt();
  13. int[] prices = new int[n];
  14. int minPrice=Integer.MAX_VALUE;
  15. for(int i=0; i<n; i++) {
  16. prices[i]=in.nextInt();
  17. minPrice=Math.min(prices[i], minPrice);
  18. }
  19. //check
  20. int do1 = minPrice+k;
  21. boolean can=true;
  22. for(int i=0; i<n; i++) {
  23. if(prices[i]>2*k+minPrice) {
  24. can=false;
  25. break;
  26. }
  27. }
  28. if(can)
  29. System.out.println(do1);
  30. else
  31. System.out.println(-1);
  32. }
  33. }
  34.  
  35. static class MyScanner {
  36.  
  37. String next() {
  38. while(st==null||!st.hasMoreTokens()) {
  39. try {
  40. st = new StringTokenizer(br.readLine());
  41. } catch (Exception e) {}
  42. }
  43. return st.nextToken();
  44. }
  45.  
  46. int nextInt() {
  47. return Integer.parseInt(next());
  48. }
  49. }
  50. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
1
3 4
1 3 6
compilation info
Main.java:4: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error
stdout
Standard output is empty