View Code of Problem 3686

#include <stdio.h>
#include <string.h>
#include <math.h>
#include<algorithm>
#include<string>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		int n, x;
		scanf("%d%d", &n, &x);
		int a[n];
		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i]);
		}
		sort(a, a + n);
		int low = 0, high = n - 1;
		int flag = 0;
		while (low <= high) {
			if (a[low] + a[high] == x) {
				flag = 1;
				break;
			}
			else if(a[low] + a[high] > x) {
				high--;
			}
			else {
				low++;
			}
		}
		if (flag == 0) {
			printf("NO\n");
		}
		else {
			printf("YES\n");
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3686