#K48667. Even Distribution of Packages
Even Distribution of Packages
Even Distribution of Packages
You are given N packages with specified weights, and M trucks, each capable of carrying at most W units of weight. The task is to determine whether it is possible to distribute all packages among the trucks so that:
- The total weight of the packages is evenly divided among the trucks.
- No truck carries a weight that exceeds its maximum capacity W.
Mathematically, if \(T = \sum_{i=1}^{N} weight_i\), then each truck must carry exactly \(\frac{T}{M}\) weight (with \(T\) divisible by \(M\)) and it must hold that \(\frac{T}{M} \le W\). You need to decide if such a distribution is possible.
inputFormat
The input is read from standard input and has the following format:
N w1 w2 ... wN M W
Where:
N
is the number of packages.w1, w2, ..., wN
are the weights of the packages.M
is the number of trucks.W
is the maximum capacity of each truck.
outputFormat
Output a single line to standard output containing either yes
if it is possible to distribute the packages evenly under the given constraints or no
otherwise.
4
2 4 6 8
2 10
yes