Advertisement
Hamoudi30

Problem G

May 14th, 2022
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 509;
  4. int a[N];
  5. int main() {
  6.     ios_base::sync_with_stdio(false);
  7.     cin.tie(nullptr);
  8.     cout.tie(nullptr);
  9. //    freopen("/home/hamoudi/Coding/run.in", "r", stdin);
  10.     freopen("overcode.in", "r", stdin);
  11.     int tt = 1;
  12.     cin >> tt;
  13.     while (tt--) {
  14.         int n;
  15.         cin >> n;
  16.         for (int i = 0; i < n; ++i) {
  17.             cin >> a[i];
  18.         }
  19. //        i need to make the ratings in ascending order
  20.         sort(a, a + n);
  21.         int ans = 0;
  22.         for (int i = 0; i < n; ++i) {
  23. //            i need to check if the difference between maximum member and current member is less than or equal 1000
  24. //            and it's a valid member (not out of range)
  25.             if (i + 5 < n && a[i + 5] - a[i] <= 1000) {
  26.                 ans++;
  27.                 i += 5; // i will skip next 5 coders
  28. //                in this case the team has been already formed
  29.             }
  30.         }
  31.         cout << ans << endl;
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement