#C9734. Flower Arrangement Problem
Flower Arrangement Problem
Flower Arrangement Problem
You are given n types of flowers, each with a specified height, and you need to determine if it is possible to arrange these flowers into m flower beds such that the height difference between any two adjacent flowers in the same bed does not exceed a given value h.
In this problem, you are provided with three integers: n, m, and h. Additionally, you are given a list of n integers representing the heights of the flowers. You must check whether the flowers can be arranged so that, after sorting them in non-decreasing order, the difference between every two consecutive flower heights is at most h (i.e. each difference satisfies \( \leq h \) ).
Note: While the value m (the number of flower beds) is provided, the condition of the problem only depends on the differences between the sorted flower heights.
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains three space-separated integers: n (the number of flower types), m (the number of flower beds), and h (the maximum allowed height difference between adjacent flowers).
- The second line contains n space-separated integers representing the heights of the flowers.
outputFormat
Output a single line to standard output (stdout) containing either YES if the arrangement is possible, or NO otherwise.
## sample5 2 2
1 5 3 7 4
YES