fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. const ll N = 1e6 + 5;
  5. ll n, b, a[N];
  6. void Task() {
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(0);
  9. cout.tie(0);
  10. if (fopen("FRIEND.inp", "r")) {
  11. freopen("FRIEND.inp", "r", stdin);
  12. freopen("FRIEND.out", "w", stdout);
  13. }
  14. }
  15.  
  16. void Solve() {
  17. cin >> n >> b;
  18. for (int i = 1; i <= n; i++) cin >> a[i];
  19. sort(a + 1, a + n + 1);
  20. ll dem = 0;
  21. for (int i = 1; i <= n; i++) {
  22. ll j1 = lower_bound(a + 1, a + n + 1, b - a[i]) - a;
  23. ll j2 = upper_bound(a + 1, a + n + 1, b - a[i]) - a - 1;
  24. if (b - a[i] < a[i]) {
  25. dem += j2 - j1 + 1;
  26. }
  27. }
  28. cout << dem << "\n";
  29. }
  30.  
  31. int main() {
  32. Task();
  33. Solve();
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
0