Codeforces 1591A - Life of a Flower Solution

  ///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  ts,sum,i,j,num;

        cin>>ts;

        while(ts--)

        {

            sum=1;

            cin>>num;

            int ar[1000],m=0;

            for(i=0; i<num; i++)

            {

                cin>>ar[i];

            }

            sum=sum+ar[0];

            for(i=1; i<num; i++)

            {

                if(ar[i-1]==0&&ar[i]==0)

                {

                    cout<<"-1"<<endl;

                    m=1;

                    break;

                }

                else if(ar[i-1]>0&&ar[i]>0)

                    sum+=5;

                else

                    sum+=ar[i];

            }

            if(m==0)

                cout<<sum<<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.