#C7471. Adjacent Resource Redistribution
Adjacent Resource Redistribution
Adjacent Resource Redistribution
You are given N houses arranged in a straight line, where each house i has a certain number of resources denoted by resources[i]. You are also given an integer Rmin which represents the minimum required resources for each house. Resources can only be transferred between adjacent houses. The task is to determine whether it is possible to redistribute the resources (by performing a series of adjacent transfers) so that every house ends up with at least Rmin resources.
A crucial observation is that if the total amount of resources is at least N × Rmin, then it is always possible to achieve the required distribution since the houses form a connected chain and resources can be moved arbitrarily along adjacent connections. In mathematical terms, the distribution is possible if and only if
\(\sum_{i=1}^{N} resources[i] \geq N \times R_{min}\)
If this inequality holds, output YES
; otherwise, output NO
.
inputFormat
The input is read from standard input (stdin
) and consists of two lines:
- The first line contains two integers: N (the number of houses) and Rmin (the minimum required resources per house).
- The second line contains N space-separated integers, where the i-th integer represents the number of resources in the i-th house.
outputFormat
Output a single line to standard output (stdout
) containing either YES
if it is possible to redistribute the resources such that every house has at least Rmin resources, or NO
otherwise.
5 10
8 12 14 9 7
YES