We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dcc32d4 commit 9680551Copy full SHA for 9680551
1928B-Equalize.cpp
@@ -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