View Code of Problem 3686

#include <iostream>
#include <algorithm>
using namespace std;
int cmp(int a, int b) {
	return a > b ? 1 : 0;
}
int main() {
	int t, n, x;
	cin >> t;
	while (t--) {
		cin >> n >> x;
		int girls[1000000]; // 1000000
		for (int i = 0; i < n; ++i)
			cin >> girls[i];
		sort(girls, girls + n);
		int low = 0, high = n - 1;
		int flag = 1;
		while (high > low) {
			if (girls[low] + girls[high] == x) {
				cout << "YES" << endl;  //大写
				flag = 0;
				break;
			}
			else if (girls[low] + girls[high] > x) --high;
			else ++low;
			
		}
		if (flag) cout << "NO" << endl;
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 3686