#C2781. Split Array into Power-of-Two Sums

    ID: 46135 Type: Default 1000ms 256MiB

Split Array into Power-of-Two Sums

Split Array into Power-of-Two Sums

You are given an array ( arr ) of ( N ) integers and an integer ( K ). Your task is to determine whether it is possible to split the array into exactly ( K ) contiguous non-empty subarrays such that the sum of the elements in each subarray is a power of two. A number ( S ) is considered a power of two if there exists a non-negative integer ( x ) such that ( S = 2^x ).

For example, if ( arr = [1, 2, 4, 8, 16] ) and ( K = 5 ), each element is itself a power of two, so the answer is YES. However, if ( K = 3 ) for the same array, no such partition exists, and the answer is NO.

The input is given via standard input and the output should be printed on standard output.

inputFormat

The first line contains two space-separated integers ( N ) and ( K ). The second line contains ( N ) space-separated integers representing the array ( arr ).

outputFormat

Print a single line with the answer: either "YES" if it is possible to split the array according to the conditions, or "NO" otherwise.## sample

5 3
1 2 4 8 16
NO