fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int const NMAX = 1e5;
  6. int const MMAX = 1e6;
  7. int n, s;
  8. int freq[1 + MMAX];
  9. int pre[1 + MMAX];
  10.  
  11. int main() {
  12. cin >> n >> s;
  13. int selfPairs = 0;
  14. for(int i = 1; i <= n; i++) {
  15. int x; cin >> x;
  16. freq[x]++;
  17. if(2*x <= s) selfPairs++;
  18. }
  19. for(int i = 1; i <= MMAX; i++) {
  20. pre[i] = pre[i-1] + freq[i];
  21. }
  22. int ans = 0;
  23. for(int i = 1; i <= s; i++) {
  24. ans += freq[i] * pre[s-i];
  25. }
  26. ans -= selfPairs;
  27. ans /= 2;
  28. cout << ans << "\n";
  29. }
Success #stdin #stdout 0.01s 9044KB
stdin
4 8
4
2
3
6
stdout
4