-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharraycolouring.cpp
More file actions
80 lines (74 loc) · 1.63 KB
/
arraycolouring.cpp
File metadata and controls
80 lines (74 loc) · 1.63 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*You are given an array consisting of n
integers. Your task is to determine whether it is possible to color all
its elements in two colors in such a way that the sums of the elements of both
colors have the same parity and each color has at least one element colored.
For example, if the array is [1,2,4,3,2,3,5,4
], we can color it as follows: [1,2,4,3,2,3,5,4
], where the sum of the blue elements is 6
and the sum of the red elements is 18
Output
For each test case, output "YES" (without quotes) if it is possible
to color the array in two colors in such a way that the sums of the elements of
both colors have the same parity and each color has at least one element colored, and "NO" otherwise.
You can output "Yes" and "No" in any case (for example, the strings "yES", "yes", and "Yes"
will be recognized as correct answers).
Sample 1
Inputcopy Outputcopy
7
8
1 2 4 3 2 3 5 4
2
4 7
3
3 9 8
2
1 7
5
5 4 3 2 1
4
4 3 4 5
2
50 48
YES
NO
YES
YES
NO
YES
YES
Note
The first sample is described in the statement.
In the second sample, there are only two colorings [4,7]
and [4,7]
, but in both cases the parity of sums is different.
In the third sample, you can color [3,9,8]
and 12
and 8
are both even.*/
#include<bits/stdc++.h>
using namespace std;
//METHOD:There should be even number of odd numbers:(e+e=e,e+o=o,o+o=e,o+o+o=o)
int main()
{
int n;
cout<<"\n enter the array size:";
cin>>n;
cout<<"\n enter array elements:";
int x,c=0;
for(int i=0;i<n;i++)
{
cin>>x;
if(x%2==1)
{
c++;
}
}
if(c%2==0)
{
cout<<"YES";
}
else
{
cout<<"NO";
}
}