My Code for DIFFVAL

My Code for DIFFVAL – Can This Be Hacked? (Need Help Understanding Logic Mistake)

I wrote the following solution for the DIFFVAL problem:

include <bits/stdc++.h>
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–){
int n,k;
string s;
cin>>n>>k>>s;
int c1=0;
int c2 =0;
for(auto &a: s){
if(a == ‘0’) c1++;
else c2++;
}

    string ans = "No";
    if(n >= 2*k){
        if(abs(c1-c2) <= 1) ans = "Yes";
    }else{
        if(min(c1,c2) >= (n-k)) ans = "Yes";
    }
 
    cout<<ans<<endl;
}
return 0;

}

You code gives wrong answer on
15 3
111111111000000
Answer is ‘Yes’ but your code output ‘No’
Possible rearrangement.
1110001110001111

wht if i chang 1 to k in second condition witch tast case not pass

include <bits/stdc++.h>
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–){
int n,k;
string s;
cin>>n>>k>>s;
int c1=0;
int c2 =0;
for(auto &a: s){
if(a == ‘0’) c1++;
else c2++;
}

    string ans = "No";
    if(n == 2*k && c1 == c2) ans = "Yes";
    else if(n > 2*k){
        if(abs(c1-c2) <= **k**) ans = "Yes";
    }
    else if(n < 2*k){
        if(min(c1,c2) >= (n-k)) ans = "Yes";
    }
 
    cout<<ans<<endl;
}
return 0;

}