fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc=new Scanner(System.in);
  14. int t=sc.nextInt();
  15. while(t-->0)
  16. {
  17. int n=sc.nextInt();
  18. int k=sc.nextInt();
  19. String str=sc.next();
  20. int ones=0,zeros=0;
  21. for(char ch:str.toCharArray())
  22. {
  23.  
  24. if(ch=='0')
  25. zeros++;
  26. else
  27. ones++;
  28.  
  29. }
  30. int min=Math.abs(zeros-ones);
  31. int unpaired=(n- 2*k)/2;
  32. int max= ((zeros)+(ones))/2;
  33. // if(zeros>=unpaired && ones>=unpaired && (zeros-unpaired)%2==0 && (ones-unpaired)%2==0)
  34. if((max-min)%2==0 &&( max-min)>=k )
  35. System.out.println("YES");
  36. else
  37. System.out.println("NO");
  38. }
  39. }
  40. }
Success #stdin #stdout 0.12s 54576KB
stdin
6
6 2
000000
2 1
01
4 1
1011
10 2
1101011001
10 1
1101011001
2 1
11
stdout
NO
NO
NO
NO
NO
NO