View Code of Problem 133

import java.util.Arrays;
import java.util.Scanner;
 
 
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		for(int i=0; i<n; i++) {
			int t = scanner.nextInt();
			int x = scanner.nextInt();
			int[] a = new int[t];
			for(int j=0; j<t; j++) {
				a[j] = scanner.nextInt();
			}
			Arrays.sort(a);
			boolean f = false;
			for(int j=0; j<t-1; j++) {
				int z = x - a[j];
				int index = Arrays.binarySearch(a, z);
				if(index > 0) {
					System.out.println("YES");
					f = true;
					break;
				}
			}
			if(!f) {
				System.out.println("NO");
			}
		}
		
		scanner.close();
	}
 
	
}

Double click to view unformatted code.


Back to problem 133