Header Ad

HackerEarth Modify Sequence problem solution

In this HackerEarth Modify Sequence problem solution Suppose we have a sequence of non-negative integers, Namely a_1, a_2, ... ,a_n. At each time we can choose one term a_i with 0 < i < n and we subtract 1 from both a_i and a_i+1. We wonder whether we can get a sequence of all zeros after several operations.


HackerEarth Modify Sequence problem solution


HackerEarth Modify Sequence problem solution.

#include <iostream>
using namespace std;

int main()
{

int n,s1=0,s2=0;
cin>>n;
int a[n];

for(int i=0;i<n;i++)

{
cin>>a[i];
}

for(int i=0;i<n;i++)

{
if (i%2==0)

{
s1=s1+a[i];
}

else

{
s2=s2+a[i];
}

}

if (s1==s2)

{
cout<<"YES";
}
else
{
cout<<"NO";
}

}

Post a Comment

0 Comments