Failing 3 test cases.Help me identifying my mistake

Revision en1, by Shellhead96, 2018-10-12 13:35:44

Probably the easiest problem I tried to approach it in different way by AP sum. Like for each step our total sum will decrease by 2 and finally stops when we reach 0 sum.

#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    long long int arr[n];
    long long int sum = 0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    /*if(sum==0)
    {
        cout<<"YES"<<endl;
        return 0;
    }*/
    long long int x = 0;
    sum = sum+2;
    x = sum/2;
    if(sum%2==0)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
    
}

I am failing at 3 test case. Is this the wrong method or I am doing something wrong.. Thanks in advance

Tags #hackerearth, #array, #series, #a easy question

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Shellhead96 2018-10-12 13:35:44 984 Initial revision (published)