View Code of Problem 3686

#include<bits/stdc++.h>
using namespace std;
int jud(int);
int main(){
	int n,x,y;
	cin>>n;
	while(n--){
		cin>>x>>y;//x是人数    y是手头有的钱 
		int num[x] = { },max = 0,f = 0;
		for(int i = 0;i<x;i++)cin>>num[i];
		sort(num,num+x);
		int i = 0,j = x-1;
		while(i<j){
			if(num[i] + num[j] == y){f = 1;break;}
			else if( num[i] + num[j] > y )j--;
			else i++;
		}
		if(f)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3686