Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
630 B
0
Indexable
Never
#define ll long long
#define pb push_back
#define ipar(arr, n) vector<ll> arr(n); for(int i=0;i<n;i++) cin>>arr[i];
#include <cmath>
using namespace std;

void solve(){
    ll n,k;cin>>n>>k;
    ipar(arr,n);
    ll ec=0;
    for(int i=0;i<n;i++){
        if(arr[i]%2==0) ec++;
    }
  
    if(k%2==1){
        cout<<ceil((double)ec/2)<<"\n";
        return;
    }
    if(k%2==0 && ec==n){
        cout<<-1<<"\n";
        return;
    }
    if(k%2==0 && ec<n){
        cout<<ec<<"\n";
        return;
    }
}


signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t;
	cin>>t;
	while(t--) solve();
}
Leave a Comment