Advertisement
jakaria_hossain

codeforce - balanced array

Apr 22nd, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL));
  5. int main()
  6. {
  7.     fast()
  8.     ll t ;
  9.     cin >> t;
  10.     while (t--)
  11.     {
  12.         ll n;
  13.         cin>>n;
  14.         ll x=n/2;
  15.         if(x%2==1)
  16.         {
  17.             cout<<"NO"<<endl;
  18.         }
  19.         else
  20.         {
  21.             ll sum=0,i,j=1;
  22.             cout<<"YES"<<endl;
  23.             for(i=0;i<n;i++)
  24.             {
  25.                 if(i<n/2)
  26.                 {
  27.                     cout<<2*(i+1)<<" ";
  28.                     sum+=(2*(i+1));
  29.                 }
  30.                 else
  31.                 {
  32.                     if(i==(n-1))
  33.                     {
  34.                         cout<<sum<<endl;
  35.                     }
  36.                     else
  37.                     {
  38.                         cout<<j<<" ";
  39.                         sum-=j;
  40.                         j+=2;
  41.                     }
  42.                 }
  43.             }
  44.  
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement