#K80247. Split Balls into Two Groups

    ID: 35488 Type: Default 1000ms 256MiB

Split Balls into Two Groups

Split Balls into Two Groups

Problem Statement:

You are given (n) balls with associated weights (w_1, w_2, \ldots, w_n) and a weight limit (W). Your task is to partition these balls into two non-empty groups (S_1) and (S_2) such that both groups satisfy the weight constraint:
(\sum_{i \in S_1} w_i \le W) and (\sum_{i \in S_2} w_i \le W).

If a valid partition exists, print "YES" in the first line followed by two lines: the first line should list the 1-indexed indices of the balls in the first group and the second line should list the indices in the second group. If no valid partition exists, print "NO".

The problem requires checking all possible non-empty partitions of the set ({1, 2, \ldots, n}) (with both groups non-empty) to find a valid partition.

inputFormat

The input is read from standard input (stdin).

The first line contains two integers (n) and (W), where (n) ((1 \le n \le 20)) is the number of balls and (W) is the maximum allowed weight for each group.
The second line contains (n) integers representing the weights (w_1, w_2, \ldots, w_n) of the balls, separated by spaces.

outputFormat

Output to standard output (stdout).

If a valid partition is found, print "YES" on the first line, followed by two lines: the first line contains the indices (1-indexed) of the balls in the first group and the second line contains the indices of the balls in the second group. If multiple solutions exist, output the partition found first by the algorithm described below.

If no valid partition exists, simply print "NO".## sample

5 10
1 2 3 4 5
YES

5 1 2 3 4

</p>