-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray_with_Odd_Sum.cpp
More file actions
34 lines (30 loc) · 845 Bytes
/
Array_with_Odd_Sum.cpp
File metadata and controls
34 lines (30 loc) · 845 Bytes
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
// we have an array of n integers
// now we can have 2 indexes i and j and replace ai with aj
// find if we can get the sum of elements of the array = odd
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
int main(){
ll testcases = 0;
cin >> testcases;
for(ll testcase = 0; testcase < testcases; testcase++){
ll n;
cin >> n;
vector<ll> a(n);
ll sum = 0;
bool odd = false;
bool even = false;
for(ll i = 0; i < n; i++){
cin >> a[i];
sum += a[i];
if(!odd && a[i] % 2 != 0)
odd = true;
else if(!even && a[i] % 2 == 0)
even = true;
}
if(sum % 2 != 0 || (odd && even)){
cout << "YES" << endl;
}
else cout << "NO" << endl;
}
}