#### sumq , codechef

codechef
sumq

question link: https://www.codechef.com/problems/SUMQ

answer link: https://www.codechef.com/viewsolution/17942109

I am pretty much sure, that my code is correct, still it is giving wrong answer.

The logic which i have used is, for a particular y, sum= (X(j) + Y) * (Z(k) +Y), where j or k can range between (0 and p) & (0 and r) repectively. Then i have expanded the sum calculating X(j)*Z(k) , Y{ X(j) + Z(k) } , Y^2 separately. Still the code is not running :'( :'(

can u point out the mistake..??

#### 1 Answer

raghav799700:01, Mar 26Raghav Grover......

p is the size of the array A, but you are using local variable whose name is also p, in the above loop,since the priority is given to local variable, hence the value of p will become 1, thats why your loop for array A runs only once;

Second thing is that the approach you are using will get TLE, since p,q and r are order of 10^5, so your approach won't work.

Hint : Use prefix sum and binary search to make your code optimised.

Please make sure the answer is not too short