-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBalanced Team.cpp
More file actions
46 lines (43 loc) · 967 Bytes
/
Balanced Team.cpp
File metadata and controls
46 lines (43 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
#define for_n(i, a, n) for (int i = a; i < n; i++)
#define ll long long
#define v(t) vector<t>
using namespace std;
void print(v(ll) v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll a;
cin >> a;
v(ll) sb;
for_n(i, 0, a) {
ll x;
cin >> x;
sb.push_back(x);
}
sort(sb.begin(), sb.end());
ll cnt = 0;
for_n(i, 0, a) {
ll left, right, target;
left = 0;
right = a - 1;
target = sb[i] + 5;
while (left < right) {
ll mid = ((left + right) / 2) + 1;
if (sb[mid] > target) {
right = mid - 1;
} else {
left = mid ;
}
}
cnt = max(cnt, left - i + 1);
}
cout << cnt << endl;
}