#C9757. Array Partitioning under Sum Constraint

    ID: 53885 Type: Default 1000ms 256MiB

Array Partitioning under Sum Constraint

Array Partitioning under Sum Constraint

You are given an array of positive integers, and two integers k and maxSum. Your task is to determine whether it is possible to split the array into exactly k contiguous subarrays such that the sum of each subarray is less than or equal to maxSum.

More formally, let the array be \(a_1, a_2, \dots, a_n\). You need to partition the array into k contiguous segments \(S_1, S_2, \dots, S_k\) such that for every segment \(S_i\), its sum \(\sum_{a \in S_i} a \le maxSum\). If such a partition exists, output "YES", otherwise output "NO".

Note: The input provided is guaranteed to have the array size first, followed by the array elements on the next line, and finally the integers k and maxSum on the third line.

inputFormat

The first line of input consists of a single integer n representing the number of elements in the array.

The second line contains n space-separated integers representing the elements of the array.

The third line contains two space-separated integers: k (the number of subarrays) and maxSum (the maximum allowed sum for each subarray).

outputFormat

Output a single line containing "YES" if there exists a way to partition the array into k contiguous subarrays where the sum of each subarray does not exceed maxSum, and "NO" otherwise.

## sample
5
7 2 5 10 8
3 15
YES

</p>