func EnsureNonDecreasingSequence(a []int64, vMin, vMax int64) {
	if vMax < vMin {
		logger.Panicf("BUG: vMax cannot be smaller than vMin; got %d vs %d", vMax, vMin)
	}
	if len(a) == 0 {
		return
	}
	if a[0] != vMin {
		a[0] = vMin
	}
	vPrev := a[0]
	aa := a[1:]
	for i, v := range aa {
		if v < vPrev {
			aa[i] = vPrev
			v = vPrev
		}
		vPrev = v
	}
	i := len(a) - 1
	if a[i] != vMax {
		a[i] = vMax
		i--
		for i >= 0 && a[i] > vMax {
			a[i] = vMax
			i--
		}
	}
}
// EnsureNonDecreasingSequence makes sure the first item in a is vMin, the last
// item in a is vMax and all the items in a are non-decreasing.
//
// If this isn't the case the a is fixed accordingly.
EnsureNonDecreasingSequence makes sure the first item in a is vMin, the last
item in a is vMax and all the items in a are non-decreasing.

If this isn't the case the a is fixed accordingly.
// EnsureNonDecreasingSequence makes sure the first item in a is vMin the last // item in a is vMax and all the items in a are non - decreasing . // // If this isn ' t the case the a is fixed accordingly .
func EnsureNonDecreasingSequence(a []int64, vMin, vMax int64) {
	if vMax < vMin {
		logger.Panicf("BUG: vMax cannot be smaller than vMin; got %d vs %d", vMax, vMin)
	}
	if len(a) == 0 {
		return
	}
	if a[0] != vMin {
		a[0] = vMin
	}
	vPrev := a[0]
	aa := a[1:]
	for i, v := range aa {
		if v < vPrev {
			aa[i] = vPrev
			v = vPrev
		}
		vPrev = v
	}
	i := len(a) - 1
	if a[i] != vMax {
		a[i] = vMax
		i--
		for i >= 0 && a[i] > vMax {
			a[i] = vMax
			i--
		}
	}
}
func EnsureNonDecreasingSequence ( a [ ] int64 , vMin , vMax int64 ) { if vMax < vMin { logger . Panicf ( " " , vMax , vMin ) } if len ( a ) == 0 { return } if a [ 0 ] != vMin { a [ 0 ] = vMin } vPrev := a [ 0 ] aa := a [ 1 : ] for i , v := range aa { if v < vPrev { aa [ i ] = vPrev v = vPrev } vPrev = v } i := len ( a ) - 1 if a [ i ] != vMax { a [ i ] = vMax i -- for i >= 0 && a [ i ] > vMax { a [ i ] = vMax i -- } } }
EnsureNonDecreasingSequence makes sure the first item in a is vMin, the last
item in a is vMax and all the items in a are non-decreasing.
EnsureNonDecreasingSequence makes sure the first item in a is vMin the last item in a is vMax and all the items in a are non - decreasing .