I have written this code for ZCO15002: https://www.codechef.com/viewsolution/15948337
I also used the same approach for ZCO13001, with this code: https://www.codechef.com/viewsolution/15948396
They seem to execute fine for small inputs, but show TLE for large ones, as can be seen below.
Any comments on how could I optimize the code, or change the approach for large test cases?
Thanks in advance!