807C: Success Rate
Why I didn’t solve it
I realize that the direct math insight might be too complicated, so I tried turning it into a search problem. Given the input range, I realize that it could be some sort of binary search, but I couldn’t model it into a clear cut range problem => the ranges are mixed. My later attempt at a math properties does not work either
Idea 1: Binary search
Instead of focusing on p/q, we can introduce a varaible t and binary search on t from 1 to 1e9, i.e., consider the final y value = p * t, we know if t is a good solution, t + 1 must be a good solution too. To test t, we just need to calculate number of new correct submissions in the formula, the result should be within [0, p * t - y]
Idea 2: Maths
based on the insight the final target we reach must be of form p * t / q * t (t >= 1), we know dy = q * t - y, dx = p * t -x, with 0 <= dx <= dy
Therefore, t >= ceiling(x / p), t >= ceil((y - x) /(q - p)). For the formula we can obviously see the two corner cases: p = 0 and q = p