#C8969. Partition Array into K Equal Sum Subsets

    ID: 53009 Type: Default 1000ms 256MiB

Partition Array into K Equal Sum Subsets

Partition Array into K Equal Sum Subsets

Given an array of integers and an integer k, determine whether the array can be partitioned into k non-empty subsets such that the sum of the elements in each subset is equal. Mathematically, if the sum of all elements is \(S\), then each subset must sum to \(\frac{S}{k}\) provided that \(S\) is divisible by \(k\). This problem can be solved using backtracking.

inputFormat

The first line contains two integers: n and k, where n is the number of elements in the array and k is the number of subsets required. The second line contains n space-separated integers.

outputFormat

Output "Yes" (without quotes) if the array can be partitioned into k subsets with equal sum; otherwise, output "No".## sample

4 2
4 3 3 2
Yes