Can anyone help me with SUMQ from JUNE17?

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

Adding “std::ios::sync_with_stdio(false);” fixed the issue. Check out https://stackoverflow.com/questions/1042110/using-scanf-in-c-programs-is-faster-than-using-cin for further details. Upvotes are still appreciated.

@godslayer12 with quicksort algo it was working later suddenly it pops out tle when i just put some more mod . adding mod to the algo in no way can change the running time as it is a constant operation and that too not in the sorting step also even if i use mergesort it is giving wa . please tell what is the issue in the code

That’s some example of self help! good going :smiley:

@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.

Can’t identify the flaw clearly, ask a question here: https://discuss.codechef.com/questions/97820/i-want-to-ask-a-question-ask-them-all-here

People will surely help

help needed !!
donno y im getting WA and TLE !!
pls help me out !!
link to my code : https://www.codechef.com/viewsolution/14251737
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 (http://ideone.com/nSLdfk). Regards.

You are making presum array in each query(B[i]). Just do it once before you start answering queries for each B[i]. Please look at my code and sorry for the late reply :frowning:

Use scanf and printf instead of cin and cout

Yeah actually that was it :stuck_out_tongue:

Hey thanks, this helped a lot :slight_smile:

This is my code : https://www.codechef.com/viewsolution/18896151
i think my approach is ok. but somehow I can’t realise the cause of WA. please help!!

Thanks btw.

avoid duplicate threads for same question… delete one of them…