fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define pb push_back
  4. #define pll pair<ll, ll>
  5. #define el "\n"
  6. using namespace std;
  7. const ll MOD = 1e9 + 7;
  8. const ll maxN = 1e5 + 5;
  9. void INIT() {
  10. ios::sync_with_stdio(0); cin.tie(0);
  11. //freopen("SOCAP.INP", "r", stdin);
  12. //freopen("SOCAP.OUT", "w", stdout);
  13. }
  14. vector<ll> a(maxN);
  15. int main() {
  16. INIT();
  17. ll n, x, ans = 0; cin >> n >> x;
  18. for(int i = 1; i <= n; i++) cin >> a[i];
  19. sort(a.begin()+1, a.begin()+n+1);
  20. for(int i = 1; i < n; i++) {
  21. if (x<a[i]) continue;
  22. ll y = x-a[i];
  23. if (binary_search(a.begin()+i+1, a.begin()+n+1,y)) ans++;
  24. }
  25. cout << ans << el;
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5280KB
stdin
8 15
5 12 6 10 9 1 2 3
stdout
3