[Solved] Can’t we use foreign libraries while doing questions on codechef and other famous coding websites?


The program has no need to store the input history. All you need is the best result so far, that being the size of the lead and the player who held it. You accumulate the score, round by round. At the end of each round, you check to see whether the current lead is larger than the previous maximum. If so, you update.

Your first problem is that you check the score differential in each round, rather than the accumulated score. Your code happens to work for the given example, in which the maximum spread happens to be at the end of round 1. You need to find the maximum lead, not merely the largest difference for a given round.

I expect that the problem is your overhead in storing all the scores and then sorting them all, is running you over the site’s time limit. You do not need a sorted list, merely the maximum value.

solved Can’t we use foreign libraries while doing questions on codechef and other famous coding websites?