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

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.