fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int t;
  7. cin >> t;
  8. while(t--)
  9. {
  10. int n,k,c=0,d=0;
  11. cin >> n >> k;
  12. string s;
  13. cin >> s;
  14. for(int i=0;i<n;i++)
  15. {
  16. if(s[i]=='0') c++;
  17. else d++;
  18. }
  19. int p = (abs(c-d))/2;
  20. if((k<p) || k>(n/2)) cout << "NO" << endl;
  21. else if((k-p)%2==0) cout << "YES" << endl; /* here k is even and p is even
  22. so, k-p is always be
  23. even;
  24. and k is odd and p is odd
  25. then k-p always be even;
  26. also we can say that
  27. (k%2==0) and (p%2==0) then
  28. cout << YEs << endl;
  29. and (k%2==1) and (p%2==1)
  30. then cout yes ;
  31. or cout no for all of two;;*/
  32. else cout << "NO" << endl;
  33.  
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0s 5324KB
stdin
6
6 2
000000
2 1
01
4 1
1011
10 2
1101011001
10 1
1101011001
2 1
11
stdout
NO
NO
YES
NO
YES
YES