LZYG - Editorial

Problem Link:- CodeChef: Practical coding for everyone


Difficulty - Cakewalk.

Prerequisites - observation of the pattern of how the used time is getting subtracted from the total allocated time.

Explanation - The time after which Sunny needs to talk with her boyfriend L can be successively subtracted from the total time and after every L amount of time K(the time Sunny takes to talk with her boyfriend)is also getting subtracted from the total time. So we can see a pattern that for every (K+L) time, some L amount of work is getting done. Hence we are using condition and a counter “res” to count how much work is done. The variable p in the code may be less than or greater than or equal to M. Depending upon the condition we need to change the output.

Complexity – O(N) where N is the no. of test cases.