fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4.  
  5. void solve()
  6. {
  7. int n, k;
  8. cin >> n >> k;
  9. vector<int> v(n);
  10. map<int, int> mp;
  11. for (int i = 0; i < n; i++)
  12. {
  13. cin >> v[i];
  14. mp[v[i]]++;
  15. }
  16. int cnt = 0;
  17. for (int i = 0; i < n; i++)
  18. {
  19. int l = k - v[i];
  20. if (mp[l] > 0)
  21. {
  22. cnt += mp[l];
  23. mp[v[i]] = 0;
  24. }
  25. }
  26. cout << cnt;
  27. }
  28. signed main()
  29. {
  30. #ifndef ONLINE_JUDGE
  31. freopen("input.txt", "r", stdin);
  32. freopen("output.txt", "w", stdout);
  33. #endif
  34. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  35.  
  36. solve();
  37. }
  38.  
Success #stdin #stdout 0.01s 5316KB
stdin
5 10
5 0 0 0 0
stdout
1