#K951. Partition Array into K Equal Sum Subsets

    ID: 38788 Type: Default 1000ms 256MiB

Partition Array into K Equal Sum Subsets

Partition Array into K Equal Sum Subsets

Given an array of positive integers (arr = [a_1, a_2, \dots, a_n]) and an integer (k), determine whether it is possible to partition the array into (k) non-empty subsets such that the sum of the elements in each subset is equal. Formally, you need to check if the array can be divided into (k) disjoint subsets each having a sum equal to (\frac{\sum_{i=1}^{n} a_i}{k}). Note that the array elements and (k) satisfy the condition that (\sum_{i=1}^{n} a_i) is divisible by (k).

inputFormat

The first line of input contains two space-separated integers (n) and (k), where (n) is the number of elements in the array and (k) is the desired number of subsets. The second line contains (n) space-separated positive integers representing the array elements.

outputFormat

Output a single line containing either "YES" if the array can be partitioned into (k) subsets with equal sum, or "NO" otherwise.## sample

4 2
4 3 2 3
YES