View Code of Problem 133

#include<stdio.h>
#include<math.h>
#include<string.h>
//#include<algorithm>
#include <bits/stdc++.h>

using namespace std;

int main() {
	int T;
	int i,j;
	scanf("%d",&T);
	while(T--) {
		int n,x;
		scanf("%d %d",&n,&x);
		int num[100001];
		for(i=0; i<n; i++) {
			scanf("%d",&num[i]);
		}
		sort(num,num+n);
		
		
		int first=0,end=n-1;
		int panduan=0;
		while(first<end) {
			if(num[first]+num[end]<x) {
				first++;
			} else if(num[first]+num[end]>x) {
				end--;
			} else {
				panduan=1;
				break;
			}
		}
		if(panduan==1) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}

}

Double click to view unformatted code.


Back to problem 133