View Code of Problem 3686

#include<bits/stdc++.h>
using namespace std;
int a[1000000];
int main(){
	int T;
	cin>>T;
	while(T--){
		int flag1=0;
		int n,x;//n个女友,x是钱 
		cin>>n>>x;
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		sort(a,a+n);
		int q=0,p=n-1;
		while(q<p){
			if(a[q]+a[p]==x){
				cout<<"YES"<<endl;
				flag1=1;
				break;
			}
			else if(a[q]+a[p]<x){
				q++;
			}
			else if(a[q]+a[p]>x){
				p--;
			}
		}
		if(flag1==0){
			cout<<"NO"<<endl;
		}
	}
}

Double click to view unformatted code.


Back to problem 3686