#K11966. Equal Sweetness Chocolate Partition
Equal Sweetness Chocolate Partition
Equal Sweetness Chocolate Partition
You are given a chocolate bar consisting of R rows and C columns. Each cell in the chocolate bar has an associated sweetness value. The task is to determine whether it is possible to partition all the pieces of the chocolate bar into k groups such that each group has the same total sweetness.
Mathematically, if \(S\) is the total sweetness of the chocolate, then each group must sum to \(\frac{S}{k}\) (with \(S\) being divisible by \(k\)).
You are allowed to form a group by selecting any subset of cells, and each cell must belong to exactly one group. Note that the groups do not need to correspond to contiguous regions of the chocolate bar.
The input is provided via standard input and the output should be printed to standard output.
inputFormat
The first line contains three integers: R, C, and k, where R and C denote the number of rows and columns of the chocolate bar, and k is the number of groups into which the chocolate should be partitioned.
This is followed by R lines, each containing C integers, representing the sweetness values of the chocolate bar's cells.
Example:
2 2 2 1 3 2 2
outputFormat
Print a single line: either Yes
if it is possible to partition the chocolate into k groups with equal total sweetness, or No
if it is not possible.
2 2 2
1 3
2 2
Yes