PLEASE DON'T DOWNVOTE WITHOUT READING BLOG,YOU CAN JUST IGNORE IT IF YOU DONT WANT TO HELP

Hey community, somedays ago there had a gym contset named "Belarusian round #2: Simran, Muskan, Divyansh, Pranjal and their problems" which had some really cool problems.

I had some idea of PROBLEM C of that contest and but it failed,and cause it has no editorial and we cant see other code I am not getting how to do this.

WHETHER YOU HAVE DONE THAT QUESTION OR NOT ,I SINCERLY HOPE THAT YOU GO THROUGH PROBLEM ONCE.

First of all this is question link: PROBLEM C

If you hadn't registered in that contest here is link to register: Belarusian round #2

AND AT LAST HERE IS FAILED APPROACH:

**WRONG LOGIC**

If there's an even number of negative numbers then the answer is product of whole array.

If there's an odd number of negative numbers, one subarray will have negative product, so obviosuly we want to minimise this and maximise the other one.

It's easy to notice that subarray will be a prefix till the first negative number, or suffix till the first negative number.

Edit:See WE cant't see accepted code

Please don't write a blog for these queries, you can always see the solutions of people who solved it.

Anyway, In this question you have to find the maximum of

`(a1*a2*⋅⋯⋅ai) + (ai+1 * ai+2 *⋅⋯⋅an)..`

for this, you can make a prefix product array and suffix product arraymodulo m, say`pref[] and suff[]`

now itterate over all possible i and do this,

`ans = max(ans, (pref[i-1]+suff[i])%MOD );`

First of all PR_0202 I have given proof that we cant see accepted code.

Secondly,I want to ask isnt that we have to minimse the negative value, so why not we chose

max(product till first time negative come +rest(pos value),in reverse producct till first time negative come+rest(positive value))

Can you tell me why this isn't optimal?

Also I think your code will not pass all test cases.

Bro try for this test case:

`1 2 3 4 5 6 7 -1000000 -1000000`

`I want to ask isnt that we have to minimse the negative value`

for this doubt, you can think over a test case where every element in the array is negative.Also, you added the proof after my comment xD

For this testcase :

`1 2 3 4 5 6 7 -1000000 -1000000`

if count of negative is even then we just return product of all array(I have even written this above)`you can think over a test case where every element in the array is negative.`

OKK let suppose I have arr={-1,-2,-3,-4,-5}so its obvious that in our answer one term is going to be pos and other negative And our ans will be maximum if we have high pos value and low neg value,,if we choose some middle index let 3 then its obvious that our pos value will reduce and negative value increases,so its always going to be optimal at both extreme.Isn't it.

Have u any corner case for this point.

Btw thanks for helping.

Your logic is correct but how will you find maximum of those two values.

you need to maximise ans, not ans%modI got this ....Thanks for helping..:)

Also, you need to maximise ans, not ans%mod.. You need to handle this in your code.

Gym contest codes are not visible to any coder who is rated lower than a candidate master.

Otherwise, You need to get

ACto see other's code.Bruh moment!

EnterYourName , Maksim1744 , Test2311 , _Chaitanya1999 can you all please share your code and idea behind that??

cpforfunCmnt You can see anyone's submission now.

In your approach let say you have even number of negative numbers, you claim that the answer is the product of array

Consider [-1,-1,2,3,4] Your claim is that the answer is 24 as per your logic ,

but we can split it as [-1,-1] and [2,3,4] to get the sum of products as 1 + 24 = 25.

NO,I am not wrong at that cause I have handled that extreme case that if first or last is one then product of rest+1...still I cant find whats wrong in my approach but I have got ac code credit:EnterYourName thanks man:)

That's not a valid credit ;)

Thanks Radhe_Loves_To_Eat ,I can see all submissions now also I got to know that u was writer of that contest ...

Here

Was it Rated or not ?

Gym Contests are unrated