# CHEFPSA Video Solution

Here it is: https://youtu.be/DkJG2GQV0WU
Commented code: https://www.codechef.com/viewsolution/28944179
Comments, questions, requests, criticism, are all welcome!

19 Likes

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

4 Likes

Can someone help me find problem in this code
https://www.codechef.com/viewsolution/28973270

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.

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.

https://www.codechef.com/viewsolution/28971136#

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)
Solution

Thanks @balrams
My code seems to fail here:

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

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.(https://www.codechef.com/viewsolution/28971460)

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)
(https://www.codechef.com/viewsolution/28884372).

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.

2 Likes

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

1
4
2 2 0 0 0 0 3 3