View Code of Problem 133

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        while (T-- > 0) {
            int n = sc.nextInt();
            int x = sc.nextInt();
            Set<Integer> set = new HashSet<>();
            int tag = 0;
            for (int i = 0; i < n; ++i) {
                int a = sc.nextInt();
                if (set.contains(x - a)) {
                    System.out.println("YES");
                    tag = 1;
                    break;
                }
                set.add(a);
            }

            if (tag == 0)
                System.out.println("NO");
        }
    }
}

Double click to view unformatted code.


Back to problem 133