View Code of Problem 133

import java.util.Scanner;

public class Main {
	public static boolean heIsX(int[] a,int x) {
		for(int i = 0;i < a.length - 1;i++) {
			for(int j = i + 1;j < a.length;j++) {
				if(a[i] + a[j] == x) {
					return true;
				}
			}
		}
		return false;
	}
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		for(int i = 0;i < t;i++) {
			int n = scanner.nextInt();
			int x = scanner.nextInt();
			int[] a = new int[n];
			for(int j = 0;j < n;j++) {
				a[j] = scanner.nextInt();
			}
			if(heIsX(a, x)) {
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 133