Two Arrays Codeforces Solution

Two Arrays Codeforces Solution

In this post, the Two Arrays Codeforces Solution is given. Question details : Codeforces Round #673 (Div. 2), problem: (B) Two Arrays.

Two Arrays Codeforces Solution

#include<bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with(false); cin.tie(0);cout.tie(0);
const int MOD = 1000000007;
#define PI = acos(-1)
using namespace std ;
int a[106];
int main()
{
int t ; cin >> t ;
while(t--)
{
int n , k ;
cin >> n >> k ;
vector<int> v(n);
for(int i = 0 ; i < n ; i++)
{
cin >> v[i];
}
if(k%2==1)
{
for(int i =0 ; i < n ; i++)
{
if(v[i] <= k/2)
v[i] = 0;
else v[i] = 1 ;
}
}
else 
{
int count = 0;
for(int i =0 ; i < n ; i++)
{
if(v[i] < k/2)
v[i] = 0;
else if(v[i]==k/2 and count%2==0)
v[i] = 0 ,count++ ;
else if(v[i]==k/2 and count%2==1)
v[i] = 1 , count++;
else if(v[i] > k/2)
v[i] = 1 ;
}
}
for(auto x : v)
{
cout << x << " " ;
}
cout << endl;
}
}


The solution of the above program is contributed by Vishal Vaibhab (IIT BHU). If you like TheCode11, then do follow us on Facebook, Twitter and Instagram.

Post a Comment

Previous Post Next Post

Contact Form