fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long ll;
  4. int main() {
  5. ios_base::sync_with_stdio(false);
  6. cin.tie(NULL);
  7. int t;
  8. cin>>t;
  9. while(t--)
  10. {
  11. int n,ans=0;
  12. cin>>n;
  13. vector<ll>v;
  14. for(int i=0;i<n;i++)
  15. {
  16. int x;
  17. cin>>x;
  18. v.push_back(x);
  19. }
  20. sort(v.begin(),v.end());
  21. ll k;
  22. cin>>k;
  23. for(int i=0;i+1<n;i++)
  24. {
  25. for(int j=i+1;j<n;j++)
  26. {
  27. ll s=v[i]+v[j];
  28. ans+=v.end()-upper_bound(v.begin()+j+1,v.end(),k-s);
  29. }
  30. }
  31. cout<<ans<<endl;
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0s 15240KB
stdin
1
10
1 2 3 4 5 6 7 8 9 10
23
stdout
7