Given an array S of size N. Determine if it is possible to add integer K (may be negative) to S_N at most L-1 times, such that S_N is then greater than all other elements in S.
If K < 0, injecting the drug will reduce his speed; so it’s better to not inject the drug at all. In this case, your friend wins only if he is faster than everyone else \implies S_N > S_i should hold for all valid i < N.
If K > 0, we can repeatedly inject the drug until the limit is reached (that is, we can inject the drug L-1 times), increasing his speed in each dose. If after this, your friend is faster than everyone else, he wins \implies S_N+K*(L-1) > S_i should hold for all valid i < N.
Since we iterate over array S once to determine the answer, the time complexity for each test case is:
Editorialist’s solution can be found here
Experimental: For evaluation purposes, please rate the editorial (1 being poor and 5 excellent)