#B4217. Beautiful Barns
Beautiful Barns
Beautiful Barns
Farmer X from CZ City owns the largest dairy farm in the city. His farm has n barns in a row, numbered from 1 to n from left to right. Some barns already have a cow with a given height and other barns are empty (represented by height 0). Farmer X wants to buy new cows (with any height in the range $[1,10^9]$) and fill the empty barns so that every barn has a cow and the cow heights are strictly increasing from left to right.
Formally, you are given an integer n and an array $H_1, H_2, \cdots, H_n$, where if the i-th barn is empty then $H_i=0$, and if it is occupied then $H_i>0$. You are allowed to replace any $0$ with an arbitrary positive integer in $[1,10^9]$. The task is to determine whether it is possible to obtain a sequence a where:
and for every index i with $H_i\neq0$, we must have ai = $H_i$. If it is possible, output any valid assignment of cows.
inputFormat
The first line contains a single integer n ($1\le n\le 10^5$), representing the number of barns.
The second line contains n space-separated integers $H_1, H_2, \dots, H_n$, where $0\le H_i\le 10^9$. If $H_i = 0$, the i-th barn is empty; otherwise, it already contains a cow of height $H_i$.
outputFormat
If there exists a valid assignment, output YES
on the first line. On the second line, output n space-separated integers representing the heights of the cows in barns from 1 to n, which form a strictly increasing sequence and respect the fixed ones.
If no valid assignment exists, output NO
.
sample
4
0 2 0 0
YES
1 2 3 4
</p>