View Code of Problem 133

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main (){
	int t, n, x;
	scanf("%d", &t);
	while(t--){
		scanf("%d%d", &n, &x);
		int a[n];
		for(int i = 0;i < n;i++){
			scanf("%d", &a[i]);
		}
		sort(a, a+n);
		int i = 0, j = n-1, flag = 0;
		while(i<j){
			if(a[i]+a[j]==x){
				flag = 1;
				break;
			}else if(a[i]+a[j]>x){
				j--;
			}else if(a[i]+a[j]<x){
				i++;
			}
		}
		if(flag) printf("YES\n");
		else printf("NO\n");
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 133