View Code of Problem 3686

#include<bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin>>t;
    while (t--){
        int n,x;
        cin>>n>>x;
        int m[100010];
        for (int i = 0; i < n; ++i) {
            cin>>m[i];
        }
        sort(m,m+n);
        int flag=0;
        int p=0,q=n-1;
        while(q>p) {
            if(m[p]+m[q]==x){
            	cout<<"YES"<<endl;
            	flag=1;
            	break;
			}
			else if(m[p]+m[q]>x){
				q--;
			}
			else{
				p++;
			}
            	
               
        }
        if(flag==0)
        cout<<"NO"<<endl;
		
    }


    return 0;
}

Double click to view unformatted code.


Back to problem 3686