#K64107. No Same Adjacent Heights
No Same Adjacent Heights
No Same Adjacent Heights
You are given N trees with initial heights and an integer D representing the number of days. In one day, you are allowed to adjust the tree heights such that they can potentially break unwanted adjacent similarities. Your task is to determine whether it is possible that after D days no two adjacent trees have the same height.
Formally, let the heights be represented as a sequence \(h_1, h_2, \dots, h_N\). Define the number of adjacent pairs with equal height as:
[ count = \sum_{i=1}^{N-1} \mathbf{1}{{h_i = h{i+1}}}, ]
The answer is "YES" if:
[ \text{either } h_1,\dots,h_N \text{ are all unique, or } D \geq count, ]
and "NO" otherwise.
inputFormat
The first line contains two integers N and D, where N is the number of trees and D is the number of days available to make adjustments. The second line contains N integers representing the initial heights of the trees.
Example:
5 2 2 3 3 2 1
outputFormat
Output a single line: "YES" if it is possible to ensure that no two adjacent trees have the same height after D days, or "NO" otherwise.
## sample5 2
2 3 3 2 1
YES
</p>