One more thing, I noticed that I got TLE in only one test case in c++ solution and got TLE in two test cases in java solution.
Why is this so as I used the same approach in both of my solutions?
Can anyone tell me how can I optimize my java solution?
I have calculated prefix sums of each of the three arrays and then just use them to derive the final result. The prefix sums helped me to get rid of every redundant calculation.
Use scanf instead of cin for taking input and Printf instead of cout your solution will be accepted.
If you have any doubt you can check this solution https://www.codechef.com/viewsolution/14137697
Can someone help me here? I was using this java code (https://pastebin.com/jrdwmx3X ) to solve this problem and I got NZEC. But when I removed the prefix sum thing first task was running fine and tle in second task (as expected), but I dont know why I was getting NZEC after applying prefix sum.
Finally I converted the same code to c++ and got AC.
Thanks.
There is no need to sort array q. You can arrive at the solution by sorting the p and r arrays , calculating the prefix sums, then doing upper bound search for each of the element of q in both p and r arrays. There is a bit of calculation involved in the last part. But removing the sorting of q array should get you an AC(I did).