#include #include #include using namespace std; bool binary_search(int key,vector a) { int left = 0, right = (int)a.size() - 1; // 配列 a の左端と右端 while (right >= left) { int mid = left + (right - left) / 2; // 区間の真ん中 if (a[mid] == key) return true;//値を返す else if (a[mid] > key) right = mid - 1; else if (a[mid] < key) left = mid + 1; } return false; } int main() { int n, x; int count = 0;//数え上げる変数 cin >> n >> x; vector data; for (int i = 0;i < n;i++) { int buff = 0; cin >> buff; data.push_back(buff); } sort(data.begin(),data.end()); for (int i = 0;i < n;i++) { int target = x - data[i]; if (binary_search(target, data))count++; } cout << count << endl; return 0; }