forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCHEF7UP.cpp
65 lines (54 loc) · 1.52 KB
/
CHEF7UP.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
55
56
57
58
59
60
61
62
63
64
65
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int t = 1;
cin >> t;
while(t--) {
int n;
cin >> n;
int x; cin >> x;
vector<int> v(n);
for(auto &i : v) cin >> i;
sort(v.begin(), v.end());
if (x > v.back()) {
int ans = 0;
for(int j = n-1;j>=0;j--) {
if(abs(v[j] - x)%2 == 1) ans++;
else break;
}
cout << ans << " " << (ans == n ? 1: -1) << '\n';
}
else if (x < v.front()) {
int ans = 0;
for(int j = 0;j<n;j++){
if(abs(v[j] - x)%2 == 1) ans++;
else break;
}
cout << ans << " " << (ans == n ? 1: -1) << '\n';
}
else{
int i = -1, j = -1;
for(int k = 0;k<n;k++) {
if (v[k] < x) i = k;
if (v[k] > x and j == -1)j = k;
}
int ans =0;
while(i >= 0 || j < n) {
int a=0, b=0;
if(i >= 0)a = abs(v[i] - x)%2;
if(j < n) b =abs(v[j] - x)%2;
if(a == 0 and b== 0)break;
if (a == 1) {
i--;
ans++;
}
if (b == 1) {
j++;
ans++;
}
}
cout << ans << " " << (ans == n ? 1: -1) << '\n';
}
}
}