WATMELON - Editorial

Add all, it will be 35, decrease arr[0] by 1(35 times)
So new array will be [-28,7,7,7,7] hence we get 0

2 Likes

anyone pls help me.

thanks bro.

2 Likes

Go through the question carefully. Its given that choose some i, and reduce the value of ai by i. You can perform this operation any number of time on any element of the array.

i think the question is not totally clear

4 Likes

We can reduce it to [ -1, -1, 1, 1]. We can reduce 17-4-4-4-4= 16, 1-2=-1 and 1-1-1=-1

[-1,-2,10] sum=7
we can also do like that
[-1, -2, 7 ]–> [-1,-4,7]–> [-1,-6,7] sum=0

no operation =3 (if we have find to min operation)

i already got that bro

can anyone tell. if we can subtract one element only once. then how this problem will be solved ??

@anon22113685 Well in that case you can subtract atmost : n * ( n + 1 ) / 2 from your sum so we will simply check

if( sum >= 0 && sum <= n*(n+1)/2 )
       cout << "YES\n" ;
else
      cout << "NO\n" ;
1 Like

logic ???

@akshy_8 With numbers 1 , 2 , 3 , 4 , 5 , . . . . . , n , we can make every possible sum between [ 1 , n*(n+1)/2 ] , Here n*(n+1)/2 is sum of first n natural numbers.

You can prove it this way using induction

Thankyou

1 Like

why the problem name was watermelon?? :thinking: :thinking: :thinking:

its super easy index sum the element @2,3,4,5 their total be 28. take 1st index to -28 ,by decreasing it by 1 each time you get 0 as totalsum now

I was thinking the question in this way…so I got wa

Thanks for the effort man

1 Like

@akshy_8 That also helped me in getting good idea of induction .

Thankyou

Yes!! I’m totally agree with you.

I think question is not clearly mention what’s it saying,
According to Question:-
choose some i, and reduce the value of a[i] by i. Find out if it’s possible to make the sum of all the integers equal to 0.
A/c to me solution is like this

int t;
cin>>t;

while(t--)

{

    int n;

    cin>>n;

    int a[n];

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

    {

        cin>>a[i];

    }

   int sum=0;

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

    {

        sum += a[i];

        sum -= i;

    }

    if(sum)  cout<<"NO\n";

    else    cout<<"YES\n";

}

So please can anyone help me out of it.