-
Notifications
You must be signed in to change notification settings - Fork 0
/
PickingNumbers.cpp
54 lines (42 loc) · 1.02 KB
/
PickingNumbers.cpp
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
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
std::vector<int> vec;
int i, g, h;
int n; //size of vector
int a;
int pos, neg; //Positive and Negatibe
int cur, tot;
int main(){
std::cin >> n;
for(i = 0; i < n; ++i){
std::cin >> a;
vec.push_back(a);
a = 0;
}
for(g = 0; g < n; ++g){
for(h = 0; h < n; ++h){
if(vec[h] < 0){
vec[h] = vec[h] * -1;
}
cur = vec[g] - vec[h];
if(cur == 0 || cur == 1){
pos++;
}
else if(cur == 0 || cur == -1){
neg++;
}
if(tot < neg || tot < pos){
if(neg >= pos){
tot = neg;
}
else if(pos >= neg){
tot = pos;
}
}
}
pos = 0;
neg = 0;
}
std::cout << tot;
return 0;
}
//Time Complexity: O(N^2)