fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void printVec(vector<char> f){
  5. for(int i=0;i<f.size();i++){
  6. cout << f[i];
  7. }
  8. cout << endl;
  9. }
  10. int main() {
  11. int t,n;
  12. cin >> t;
  13. while(t--){
  14. cin >> n;
  15. vector<int> a(n);
  16. int one = 0, two = 0;
  17. for(int i=0;i<n;i++){
  18. cin >> a[i];
  19. a[i] == 1 ? one++ : two++;
  20. }
  21. if(2*((one + 2*two)/2) != (one + 2*two)) cout << "no\n";
  22. else if(two == 0 && one % 2 != 0) cout << "no\n";
  23. else if(one == 0 && two % 2 != 0) cout << "no\n";
  24. else if(one > 0 && two > 0 && one % 2 != 0 && two % 2 != 0) cout << "no\n";
  25. else cout << "yes\n";
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5276KB
stdin
6
2
1 1
2
1 2
4
1 2 1 2
3
2 2 2
3
2 1 2
5
2 1 1 1 1 
stdout
yes
no
yes
no
no
yes