View Code of Problem 133

#include<iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;
int main(){
	int t;
	scanf("%d",&t);
	for(int i=0;i<t;i++){
		int n,x;
		scanf("%d%d",&n,&x);
		int ss[n]={};
		for(int j=0;j<n;j++){
			scanf("%d",&ss[j]);
		}
		sort(ss,ss+n);
		int s1[n]={};
		int count=0;
		for(int j=0;j<n;j++){
			if(ss[j]<x){
				s1[count++]=ss[j];
			}
		}
		int flag=0;
		for(int j=0;j<count;j++){
			for(int k=j+1;k<count;k++){
				if(s1[j]+ss[k]==x){
					flag=1;
					break;
				}
			}
		}
		if(flag)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
} 

Double click to view unformatted code.


Back to problem 133