#K40692. Equal Subset Partition for K Subsets

    ID: 26699 Type: Default 1000ms 256MiB

Equal Subset Partition for K Subsets

Equal Subset Partition for K Subsets

Given an array of integers and an integer k, determine whether it is possible to partition the array into k subsets such that the sum of the elements in each subset is equal. In mathematical terms, let the total sum of elements be \(S\) and the target for each subset be \(T = S/k\). The partition is only possible if \(S\) is divisible by \(k\), and there exists a way to form k subsets each summing to \(T\).

Note: The input is read from stdin and the answer should be printed to stdout as either True or False.

inputFormat

The input is given via stdin over three lines:

  1. The first line contains an integer k, the number of subsets.
  2. The second line contains an integer n, which is the number of elements in the array.
  3. The third line contains n space-separated integers representing the elements of the array.

outputFormat

Output a single line to stdout: True if the array can be partitioned into k subsets with equal sum, otherwise False.

## sample
4
7
4 3 2 3 5 2 1
True

</p>