#K12111. Partition Array into Two Subsets under Sum Constraint

    ID: 23619 Type: Default 1000ms 256MiB

Partition Array into Two Subsets under Sum Constraint

Partition Array into Two Subsets under Sum Constraint

You are given an array of n positive integers and an integer threshold t. Your task is to determine whether it is possible to partition the array into two subsets such that the sum of each subset is less than or equal to t.

Let \(S\) be the sum of all elements in the array. If \(S > 2t\), then it is impossible to partition the array as required.

You need to check if there exists a subset with sum \(s\) (where \(0 \le s \le t\)) such that the sum of the other subset \(S - s\) is also \(\le t\). Formally, find if there exists an integer \(s\) such that:

[ \begin{aligned} &0 \le s \le t,\ &S - s \le t. \end{aligned} ]

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

inputFormat

The input is given via standard input and consists of two lines:

  • The first line contains two space-separated integers: n (the number of elements in the array) and t (the threshold for each subset's sum).
  • The second line contains n space-separated positive integers representing the array elements.

outputFormat

Output a single line to standard output containing either YES if the array can be partitioned into two subsets meeting the criteria, or NO if it cannot.

## sample
4 10
2 4 6 8
YES