You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
600 B
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> v1(n), v2;
v2.reserve(n * (n - 1) / 2);
for (auto &x : v1)
cin >> x;
for (int i = 0; i < n; i++)
for (int j = 0; j < i; j++)
v2.push_back(v1[i] + v1[j]);
sort(v2.begin(), v2.end());
cout << count_if(v1.begin(), v1.end(), bind(binary_search<decltype(v2)::iterator, decltype(v2)::value_type>, v2.begin(), v2.end(), placeholders::_1));
return 0;
}