View Code of Problem 133

import java.util.*;
public class Main {
	public static void main(String[] args) {
       Scanner in=new Scanner(System.in);
      int t=in.nextInt();
      while(t>0) 
      {
    	  boolean flag=false;
    	  HashSet<Long>a=new HashSet<>();
    	  int n=in.nextInt();
    	  long x=in.nextLong();
    	for(int i=0;i<n;i++) 
    	  {
    		long b=in.nextLong();
    		  if(a.contains(x-b)) {
    			  flag=true;
    			  break;
    		  }
    		  else {
    			  a.add(b);
    		  }	  
    	  }
    	  if(flag) {
    		  System.out.println("YES");
    	  }else {
    		  System.out.println("NO");
    	  }
    	  t--;   	  
      }
	} 
}

Double click to view unformatted code.


Back to problem 133