fork download
  1.  
  2. #include <iostream>
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5. #define pb push_back
  6. #define ll long long
  7.  
  8. const ll N= 2e6;
  9. ll fact[N];
  10.  
  11. ll cnk(ll a , ll b){
  12. return fact[a] / (fact[b] * fact[a-b]) ;
  13. }
  14.  
  15.  
  16. void solve() {
  17. ll n;
  18. cin>>n;
  19. vector<ll> v (n);
  20. for (int i=0; i<n; ++i){
  21. cin>>v[i];
  22. }
  23. if (n<6) {
  24. cout<<0<<endl;
  25. return;
  26. }
  27. if (n==6) {
  28. for (int i=1; i<n; ++i){
  29. if (v[i]-v[i-1]>1000){
  30. cout<<0<<endl;
  31. return;
  32. }
  33. }
  34. }
  35. if (n==6) {
  36. cout<<1<<endl;
  37. return;
  38. }
  39.  
  40. sort (v.begin(), v.end());
  41. queue<ll> theGroup;
  42. theGroup.push(v[0]);
  43. ll p1, p2;
  44. p1=0;
  45. p2=1;
  46. cout<<n<<endl;
  47. ll ans=0;
  48. while(p2<n){
  49. while (v[p2]-v[p1]<=1000){
  50. theGroup.push(v[p2]);
  51. ++p2;
  52. }
  53. ++p1;
  54. if (theGroup.size()>=6) ans+=cnk(theGroup.size(), 6);
  55. theGroup.pop();
  56. }
  57.  
  58. cout<<ans<<endl;
  59. }
  60.  
  61. int main() {
  62. ios::sync_with_stdio(false);
  63. cin.tie(nullptr);
  64. ll t=1;
  65. cin>>t;
  66. fact[0]=1;
  67. for (int i=1; i<N; ++i) fact[i]= i* fact[i-1];
  68. while (t--) solve();
  69.  
  70. return 0;
  71. }
Success #stdin #stdout 0.01s 19268KB
stdin
1
13
7 9 7 2 1000 1001 2 3 9 4 5 2 5
stdout
13
12376