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 925 (Div. 3) 1931D. Divisible Pairs Solution

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

Powered by Blogger.