File tree Expand file tree Collapse file tree 1 file changed +65
-0
lines changed Expand file tree Collapse file tree 1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+
5
+ int main () {
6
+ ios_base::sync_with_stdio (false );
7
+
8
+ int t = 1 ;
9
+ cin >> t;
10
+ while (t--) {
11
+ int n;
12
+ cin >> n;
13
+ int x; cin >> x;
14
+ vector<int > v (n);
15
+ for (auto &i : v) cin >> i;
16
+
17
+ sort (v.begin (), v.end ());
18
+
19
+ if (x > v.back ()) {
20
+ int ans = 0 ;
21
+ for (int j = n-1 ;j>=0 ;j--) {
22
+ if (abs (v[j] - x)%2 == 1 ) ans++;
23
+ else break ;
24
+ }
25
+ cout << ans << " " << (ans == n ? 1 : -1 ) << ' \n ' ;
26
+ }
27
+ else if (x < v.front ()) {
28
+ int ans = 0 ;
29
+ for (int j = 0 ;j<n;j++){
30
+ if (abs (v[j] - x)%2 == 1 ) ans++;
31
+ else break ;
32
+ }
33
+ cout << ans << " " << (ans == n ? 1 : -1 ) << ' \n ' ;
34
+ }
35
+ else {
36
+ int i = -1 , j = -1 ;
37
+ for (int k = 0 ;k<n;k++) {
38
+ if (v[k] < x) i = k;
39
+ if (v[k] > x and j == -1 )j = k;
40
+ }
41
+ int ans =0 ;
42
+
43
+ while (i >= 0 || j < n) {
44
+ int a=0 , b=0 ;
45
+ if (i >= 0 )a = abs (v[i] - x)%2 ;
46
+ if (j < n) b =abs (v[j] - x)%2 ;
47
+ if (a == 0 and b== 0 )break ;
48
+
49
+ if (a == 1 ) {
50
+ i--;
51
+ ans++;
52
+ }
53
+ if (b == 1 ) {
54
+ j++;
55
+ ans++;
56
+ }
57
+ }
58
+ cout << ans << " " << (ans == n ? 1 : -1 ) << ' \n ' ;
59
+
60
+ }
61
+
62
+ }
63
+
64
+
65
+ }
You can’t perform that action at this time.
0 commit comments