Codeforces 1343B B. Balanced Array Solution
Solution in c++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<iostream>
using namespace std;
int main()
{
int t,n,i,e,c,co,s,se,o;
cin>>t;
while(t--)
{
co=0,c=0,s=0,se=0;
cin>>n;
if(n%4==0)
{
cout<<"YES"<<endl;
e=n/2;
o=n/2;
for(i=0;; i=i+2)
{
c++;
if(c>e)
break;
else
{
cout<<i+2<<" ";
se=se+(i+2);
}
}
for(i=-1;; i=i+2)
{
co++;
if(co+1>o)
break;
else
{
cout<<i+2<<" ";
s=s+(i+2);
}
}
cout<<se-s<<endl;
}
else
cout<<"NO"<<endl;
}
}
No comments