Editorial
Let . The recurrence can be rewritten as
There are at most four unknowns: . Moreover,
Therefore, if , then , which bounds all seed values.
Fix in turn. Enumerate . Use the sum of the chosen values and the minimum possible remaining values to discard candidates that cannot satisfy .
Once these values are fixed, increasing never decreases any prefix sum or later sequence term. Thus, binary search between and . While evaluating the recurrence, cap every value above at to avoid overflow.
There are at most five possible values of . The time complexity is , where . The space complexity is .
Solution written by GPT6