File tree 1 file changed +54
-0
lines changed
1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ std::vector<int > vec;
4
+ int i, g, h;
5
+ int n; // size of vector
6
+ int a;
7
+ int pos, neg; // Positive and Negatibe
8
+ int cur, tot;
9
+
10
+ int main (){
11
+ std::cin >> n;
12
+ for (i = 0 ; i < n; ++i){
13
+ std::cin >> a;
14
+ vec.push_back (a);
15
+ a = 0 ;
16
+ }
17
+
18
+ for (g = 0 ; g < n; ++g){
19
+ for (h = 0 ; h < n; ++h){
20
+ if (vec[h] < 0 ){
21
+ vec[h] = vec[h] * -1 ;
22
+ }
23
+
24
+ cur = vec[g] - vec[h];
25
+ if (cur == 0 || cur == 1 ){
26
+ pos++;
27
+ }
28
+ else if (cur == 0 || cur == -1 ){
29
+ neg++;
30
+ }
31
+
32
+
33
+ if (tot < neg || tot < pos){
34
+
35
+ if (neg >= pos){
36
+ tot = neg;
37
+ }
38
+
39
+ else if (pos >= neg){
40
+ tot = pos;
41
+ }
42
+
43
+ }
44
+
45
+ }
46
+
47
+ pos = 0 ;
48
+ neg = 0 ;
49
+ }
50
+ std::cout << tot;
51
+ return 0 ;
52
+ }
53
+
54
+ // Time Complexity: O(N^2)
You can’t perform that action at this time.
0 commit comments