Can anyone help me with SUMQ from JUNE17 ?

CodeChef: Practical coding for everyone Can anyone help me with optimizing my solution? I’m getting TLE in sub-task #4 and 0.91s execution time for sub-task #5. Upvotes will be appreciated since I don’t have permission to post any new questions.

Can any one please tell me what is wrong with my code i have first sorted A and C array and then i have used upper bound stl function to determine the contribution of each element of B in the answer.This is what i tried
https://www.codechef.com/viewsolution/14196681

@siddharthp538 Hey I understood the approach and followed it, still getting a TLE for larger inputs.
Pls help me out.

https://www.codechef.com/viewsolution/14247678

1 Like

Please help me too, i had made this code for scoring 100 points as per the given constraints.
I keep getting WA in some test cases, and i am not able to identify the case.
Please help me

https://www.codechef.com/viewsolution/14080761

Thank you.

help needed !!
donno y im getting WA and TLE !!
pls help me out !!
link to my code : CodeChef: Practical coding for everyone
thanks in advance :slight_smile:

a far more simple approach will br just twist the formula …
lets go with the test case given …
sort the 1st and 3rd arrays!
store their presums in two different arrays,sum1 and sum2

now just transverse in the 2nd array from 1st elemnt to lst elmnt … and suppse in the tst case we get 1st elemnt as 5 then using upper bound find the uppr bound of 5 in the 1st array and then the upper bound in the 3rd array … you get the elemnts as (1,2,3) and (4,5) ,use binary srch to do rther then linear search ,…
now twick the formula to ((1+2+3)+(3 * 5)) * ( (4+5)+(2 * 5))
do it for every elemnt in the 2ND ARRAY… here 3 * 5 (3 refers to the count of elemnts less then equals 5) and 2 * 5 , 2 the no of elemnts less then equals 5 .
keep doing it for all elemnts and then just simply print the answer…

do use modulo in every summation steps carefully.else u may get a wrng answer …
here’s my code for reference !
https://www.codechef.com/viewsolution/14087847

What’s wrong with my implementation ?? I know it’s not optimized but is should work for small subtask :frowning:
any help would be appreciated.
https://www.codechef.com/viewsolution/14059882

Sorry for posting this here(lack of karma points :|) ; I had adopted a similar approach to the one mentioned in the comments; however I got a WA for all my testcases. I would be thankful if anyone could take a look (nSLdfk - Online C++ Compiler & Debugging Tool - Ideone.com). Regards.

This is my code : CodeChef: Practical coding for everyone
i think my approach is ok. but somehow I can’t realise the cause of WA. please help!!

Thanks btw.

I did try that, but it didn’t work.
I think the formula i wrote needs some modifications and adjustments to handle the overflow.

Okay thanks lemme try that.

got my mistake, will try in practice section

Enjoy the karma.

1 Like

U’re doing the same mistake i mid, break down your formula, use modulus properties and take modulus at each step

Just a link to ideone could have helped…

3 Likes

Haha, exactly my point. :stuck_out_tongue:

Image of code is worse. What do we do to that image? We can atleast copy paste code to debug it.

After simplifying above calculation the formula which we get is
(( 3 * X)+(a+b+c) ) * ((2 * X)+(j+k))

How did you arrive at this result? I will appreciate hints on the thought process since i tried hard but couldnt simplify the function.

2 Likes

@vijju123 thanks !

1 Like

Enjoy the karma and thanks !