Блог пользователя Shellhead96

Автор Shellhead96, история, 6 лет назад, По-английски

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

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

The algorithm is incorrect, consider input

2
2 4

The sequence can't be modified into all zeros, but (sum of elements + 2) is even and your algorithm outputs YES.