View Code of Problem 3686

#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int T;
	cin>>T;
	while(T--){
		int n,x;
		cin>>n>>x;
		int a[n];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		sort(a,a+n);
		int low=0,high=n-1;
		while(low<high){
			if(a[low]+a[high]==x){
				printf("YES\n");
				break;
			}else if(a[low]+a[high]<x){
				low++;
			}else{
				high--;
			}
		}
		if(low==high){
			printf("NO\n");
		}
	}
}

Double click to view unformatted code.


Back to problem 3686