#K41477. Partition Array into Prime Sum Subsets

    ID: 26874 Type: Default 1000ms 256MiB

Partition Array into Prime Sum Subsets

Partition Array into Prime Sum Subsets

You are given an array of n integers and an integer k. Your task is to determine whether it is possible to partition the entire array into exactly k non-empty subsets such that the sum of the elements in each subset is a prime number.

Each element must belong to exactly one subset. A prime number is defined as a natural number greater than or equal to 2 that has no positive divisors other than 1 and itself. In mathematical notation, a number \(p\) is prime if and only if \(p \ge 2\) and \(\nexists\, d\) with \(1 < d < p\) such that \(d \mid p\).

If such a partition exists, print YES; otherwise, print NO.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  • The first line contains two integers \(n\) and \(k\) separated by a space, where \(n\) is the number of elements in the array.
  • The second line contains \(n\) space-separated integers representing the array.

outputFormat

Output a single line to standard output (stdout) containing either YES if the array can be partitioned into exactly k subsets with prime sums, or NO otherwise.

## sample
5 2
3 8 12 5 13
YES