View Code of Problem 133

#include <iostream>

using namespace std;

const int maxn = 1000001;

int main()
{
    int t;
    cin >> t;

    int n,x;
    while (t--){
        cin >> n >> x;
        int  a[n] = {0};
        int flag[n] = {0};
        for(int i = 0; i < n; i++){
            cin >> a[i];
            flag[a[i]]++;

        }
        for(int i = 0; i < n; i++){
            if (x != 2 * a[i]){
            if(flag[x-a[i]] == 1)
            {
                cout << "YES"<<endl;
                break;
            }
            else{
                cout << "NO"<<endl;
                break;
            }
            }
            else{
                if(flag[x-a[i]] > 1){
                    cout << "YES"<<endl;
                    break;
                }
                else{
                    cout <<"NO" <<endl;
                    break;
                }
            }


        }
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 133