CHEFPSA Video Solution

Here it is:
Commented code:
Comments, questions, requests, criticism, are all welcome!


ThankYou. I appreciate your effort of putting video solutions just after finishing of contest


Can someone help me find problem in this code

Just a question , are you checking presence of x-a[i] in array.

It will be there i think cause without it sum % (n+1) would not be 0

Have you tried:
n=3, sum=4
1, 1, 2, 0, 0, 0

Please do video solution for ARMYOFME as well. :sweat_smile:

yep tried ans coming out to be 0 as expected

@tmwilliamlin I’ve done exactly what you’ve mentioned.
(I agree with the TLE because I’m calculating factorials in a very slow way.)

But, can anyone help me point out why WA in some test cases, while AC in some.

First of all reason to TLE, You are taking long input array using input() take inputs using readline()
Second… I think in your solution you have assumed that all inputs are valid prefix suffix sum array.

Look at my Submission (with Detailed Analysis and Explanation)

Thanks @balrams
My code seems to fail here:

I was considering a pair to valid when its sum is equal to max element. (:disappointed:

Yes, exactly bcz its not neccesary that array sum is maximum always. there can be negative values in your original array which can make sum to less. So, better to check for sum is to find pairs such that multiplication with (n+1) gives the sum of whole input sum.
And It can be proved. during contest, I verified this for almost all type of inputs.

kindly have a look. I don’t know where it went wrong for some test cases.(

Can someone please have a look. Same logic code was running well in Python(Giving TLE in 6th Subtask) but showing wrong answer in C++(In 4 Subtasks)
Please take a look.

1 Like

My code also fails in those testcases
UPD: Okay I understood my mistake , I am not checking sum(a)%(n+1)==0

Stay tuned, I’m working on it.


I think this test case will cause your solution to fail:

2 2 0 0 0 0 3 3

Answer should be 0.

Yeah, He is

Same logic… Everything same but still 1 TLE who stole my 80 points😅

Try changing all ‘endl’ with “\n” in your code.