Skip to content

Commit 9680551

Browse files
committed
Create 1928B-Equalize.cpp
1 parent dcc32d4 commit 9680551

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

1928B-Equalize.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <cstdio>
2+
#include <vector>
3+
#include <set>
4+
#include <algorithm>
5+
6+
int main(){
7+
8+
long t; scanf("%ld", &t);
9+
while(t--){
10+
long n; scanf("%ld", &n);
11+
std::vector<long> v; std::set<long> s;
12+
for(long p = 0; p < n; p++){
13+
long x; scanf("%ld", &x);
14+
if(s.count(x)){continue;}
15+
v.push_back(x); s.insert(x);
16+
}
17+
18+
sort(v.begin(), v.end());
19+
//for(long p = 0; p < v.size(); p++){printf("* %ld\n", v[p]);}
20+
21+
long idx(0); long ans(0);
22+
for(long p = 0; p < v.size(); p++){
23+
while(idx + 1 < v.size() && v[idx + 1] < v[p] + n){++idx;}
24+
long len = idx - p + 1;
25+
ans = (ans > len) ? ans : len;
26+
if(idx + 1 == v.size()){break;}
27+
}
28+
29+
printf("%ld\n", ans);
30+
}
31+
32+
}

0 commit comments

Comments
 (0)