fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. const int N = 4e5 + 5;
  7. int n , k;
  8. int a[N];
  9. int cnt[N];
  10.  
  11. main()
  12. {
  13. ios::sync_with_stdio(0);
  14. cin.tie(0);
  15. cin >> n >> k;
  16. for(int i = 1 ; i <= n ; i++)
  17. cin >> a[i];
  18. int ans = 0;
  19. /// ay + az = k - ax
  20.  
  21. for(int y = 1 ; y <= n ; y++)
  22. {
  23. for(int z = y + 1 ; z <= n ; z++)
  24. {
  25. ans += cnt[a[y] + a[z] + (int)2e5];
  26. }
  27. cnt[k - a[y] + (int)2e5]++;
  28. }
  29. cout << ans;
  30.  
  31. /// 0 <= a[y] + a[z] + 2e5 <= 4e5
  32. /// 0 <= k - ay + 2e5 <= 4e5
  33.  
  34.  
  35.  
  36. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty