#C5372. Organize Bulbs in Zones
Organize Bulbs in Zones
Organize Bulbs in Zones
You are given n zones and a list of n integers representing the required number of bulbs for each zone. You are also given an integer d which represents the maximum allowed difference between the number of bulbs in two consecutive zones after arranging them.
The task is to determine whether it is possible to arrange the bulbs in non-decreasing order such that the difference between any two consecutive zones does not exceed d. If it is possible, print possible
followed by the sorted list of bulbs. Otherwise, print impossible
.
In mathematical terms, after sorting the array b (where b[i] represents the number of bulbs in the i-th zone), the condition is:
$$ b_{i} - b_{i-1} \le d \quad \text{for all } i=2,3,\ldots,n. $$inputFormat
The first line contains two space-separated integers n and d, where n is the number of zones and d is the maximum allowed difference between consecutive zones.
The second line contains n space-separated integers representing the number of bulbs required for each zone.
Input is provided via standard input (stdin).
outputFormat
If an arrangement is possible, output two lines: the first line should be the string possible
, and the second line should contain the sorted arrangement of bulbs separated by spaces.
If it is impossible to arrange the bulbs such that consecutive differences do not exceed d, output a single line containing impossible
.
Output should be written to standard output (stdout).
## sample5 3
1 4 5 2 6
possible
1 2 4 5 6
</p>