You are given an array of nonnegative integers.
Construct an integer array of length such that:
If no such array exists, output . Otherwise, output any valid array.
If no valid array exists:
The prefix sums are , so each integer from to appears exactly once. Every element of the output also satisfies its corresponding bound.
The first prefix sum must be or . If it is , no allowed value of gives a new positive prefix sum. If it is , then is forced. The third prefix sum is then at most , so it must be . Since , the fourth prefix sum cannot be the remaining value . Thus no valid array exists.
The only prefix sum is , and holds.