Codeforces Global Round 19 1637C - Andrew and Stones Solution



 

Solution in C++: 

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long t,n,i,odd,ocnt;
    cin>>t;
    while(t--)
    {
        odd=0;
        ocnt=0;
        cin>>n;
        long long a[n+9];
        for(i=0; i<n; i++)
            cin>>a[i];
        for(i=1; i<n-1; i++)
        {

            ocnt+=a[i]/2;
            if(a[i]%2==1)
                odd++;
        }
        if(ocnt==0)cout<<"-1"<<endl;
        else if((n==3)&&(a[1]%2==1))cout<<"-1"<<endl;
        else cout<<ocnt+odd<<endl;
    }
    return 0;
}

4 comments:


  1. Hi, I am Jennifer from Web Magazine and Newsin USA your blogs really help us to develop our skills, I appreciated more articles to gather knowledge.

    ReplyDelete

  2. Hi, I am Jennifer from Web Magazine and Newin USA your blogs really help us to develop our skills, I appreciated more articles to gather knowledge.

    ReplyDelete
  3. Thanks Jennifer for inspring commen and you blog site is very good. If you want to friendship with me ? Please contact this email: ahtonmoy16@gmail.com

    ReplyDelete

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.