+ 3

Why my code throws time limit exceeded warning?

I am currently solving a problem on codechef, now i have written a code that outputs the correct answer for subtask2, as i was confused about how to implement logic for subtask 1. but my code submission throws TLE, what could be the better and cleanest way to ensure the time complexity. Also if someone can guide me through the subtask 1 logic, as i cannot determine how to check whether there is draw in the match(as per the problem). Any help is highly appreciated! Thanks here is the problem link on codechef: https://www.codechef.com/ICO20MCK/problems/SINGTOUR here is the code link: https://code.sololearn.com/cINy84162eiv

27th Nov 2019, 6:31 PM
Pranshu Ranjan
Pranshu Ranjan - avatar
7 Antworten
+ 3
Gaurav Agrawal Got it , but how can I test for a draw match ? What logic should I implement ? BTW thanks for your valuable reply
28th Nov 2019, 7:40 PM
Pranshu Ranjan
Pranshu Ranjan - avatar
+ 3
pitch values for a singer: {$L, L+1, L+2, ..., U-1, $U} 1)equal range will be draw: ●------------------------------------● 2)lower limit <$L and upper limit <$U will lead to draw: <------------------------------------< 3)lower limit >$L and upper limit >$U will lead to draw: >------------------------------------> //to improve time complexity more, you can use nC2 comparisions instead of (n-1)*n comparisions.
29th Nov 2019, 4:01 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 2
hey, Gaurav Agrawal I have updated my question details and added the links of the problem and the code along, please review it and guide me.
28th Nov 2019, 9:32 AM
Pranshu Ranjan
Pranshu Ranjan - avatar
+ 2
Hey Gaurav Bhaiya thanks for your answer I will try it for sure and will update here . Thanks for your valuable time !
30th Nov 2019, 1:47 AM
Pranshu Ranjan
Pranshu Ranjan - avatar
+ 1
I believe you are using BufferReader instead of Scanner as it is more efficient. If you are facing TLE then its the problem in your logic. Please post exact problem and the code which you have written(unable to view on reddit), me or some community member can try.
28th Nov 2019, 7:35 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
Pranshu Ranjan -use BufferReader instead of Scanner -you don't need to look for every pitch in range to compare two singers, looking boundary pitches(lowest and highest) are enough to compare two singers.
28th Nov 2019, 4:20 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
Hey Gaurav Bhaiya , ahh! I forgot to update you , thanks for your answer now it's works . Thank you very much for your valuable time .
4th Dec 2019, 4:40 PM
Pranshu Ranjan
Pranshu Ranjan - avatar