View Code of Problem 133

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#define N 100
using namespace std;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,x,leap=0,flag=0;
		scanf("%d%d",&n,&x);
		int str[n];
		for(int i=0;i<n;i++)
			scanf("%d",&str[i]);
		sort(str,str+n);
		for(int i=0,j=n-1;i<j;)
		{      //调节器
		    if(str[i]+str[j]==x)
			{
		        leap=1;
		        break;
		    }
			else if(str[i]+str[j]<x)
		        i++;
		    else
		        j--;
		}
		if(leap==1)
			printf("YES\n");
		else
			printf("NO\n");
	}
}

Double click to view unformatted code.


Back to problem 133