fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Solver
  9. {
  10.  
  11. public boolean SolverUtil(int a[],int x)
  12. {
  13. Arrays.sort(a);
  14. int End = a.length;
  15. int cnt=0;
  16. for(int i=0;i<End-1;i++)
  17. {
  18. if(Binsearch(a,x-a[i],0,End,i))
  19. return true;
  20. }
  21. return false;
  22.  
  23. }
  24. public boolean Binsearch(int a[],int N,int low,int high, int pivot)
  25. {
  26. int mid=(low+high)/2;
  27. if(a[mid]==N && mid!=pivot)
  28. return true;
  29. if(low<high)
  30. {
  31. if(a[mid]>N)
  32. return Binsearch(a,N,low,mid-1,pivot);
  33. else if(a[mid]<N)
  34. return Binsearch(a,N,mid+1,high,pivot);
  35. }
  36. return false;
  37. }
  38. }
  39. public class Main
  40. {
  41. public static void main(String[] args)
  42. {
  43. int A[] = {1, 5, 9, 12, 24};
  44. Solver ob1 = new Solver();
  45. if(ob1.SolverUtil(A,18))
  46. System.out.println("Yes");
  47. else System.out.println("No");
  48.  
  49. }
  50.  
  51. }
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
No