A run ascending list is a list such that runs of consecutive equal elements are strictly increasing in length. For example [1,1,2,2,1,1,1]
can be split into three runs [[1,1],[2,2],[1,1,1]]
with lengths [2,2,3]
, since two runs are the same length this is not a run ascending list. Similarly [2,2,1,3,3,3]
is not run ascending since the second run ([1]
) is shorter than the first ([2,2]
). [4,4,0,0,0,0,3,3,3,3,3]
is run ascending since the three runs strictly increase in length.
An interesting challenge is to figure out for a particular set of symbols whether they can be arranged into a run ascending list. Of course the values of the individual symbols don't matter. It just matters how many of each there are.
In this challenge you will be given a list of \$n\$ positive integers, \$x_i\$, as input. Your task is to determine if a run ascending list can be made from the numbers \$1\$ to \$n\$ with each number \$k\$ appearing exactly \$x_k\$ times.
For example if the input is [4,4,7]
it means you must determine if a run ascending list can be made with four 1s, four 2s and seven 3s. The answer is yes:
[1, 3,3, 1,1,1, 2,2,2,2, 3,3,3,3,3]
If the input is [9,9,1]
it means you must try to find a run ascending list made of nine 1s, nine 2s and one 3. This cannot be done. It must start with the single 3
since that run can only be 1 long. Then the 1s and 2s must alternate to the end, since each run must larger than the previous, there must be more of whichever number goes last.
Rules
You should take as input a non-empty list of positive integers. You should output one of two distinct values. One if a run ascending list can be made the other if it cannot.
This is code-golf the goal is to minimize the size of your source code as measured in bytes.
Testcases
Inputs that cannot make a run ascending list
[2,2]
[40,40]
[40,40,1]
[4,4,3]
[3,3,20]
[3,3,3,3]
Inputs that can make a run ascending list
[1]
[10]
[6,7]
[7,6]
[4,4,2]
[4,4,7]
[4,4,8]