#C5553. Closest Subset Sum

    ID: 49215 Type: Default 1000ms 256MiB

Closest Subset Sum

Closest Subset Sum

You are given n cards, each with an integer value, and a target sum T. Your task is to select a non-empty subset of cards such that the total sum of the selected cards is as close as possible to T in terms of absolute difference. In case of a tie (i.e., two subsets having the same absolute difference from T), choose the subset with the greater total sum.

The answer should include the closest total sum, the number of cards in the chosen subset, and the list of card values in that subset. All input will be provided from standard input (stdin) and your output should be printed to standard output (stdout).

Formally, if the chosen subset has a sum S, then S should minimize
\( |S - T| \) over all non-empty subsets of the cards. If more than one subset gives the same value of \( |S - T| \), choose one with the maximum \( S \).

inputFormat

The first line contains two integers n and T separated by a space, where n is the number of cards and T is the target sum. The second line contains n space-separated integers representing the values on the cards.

outputFormat

Print three outputs separated by spaces: the closest sum S, the number of cards in the subset, and the card values of the chosen subset.

## sample
5 10
2 3 7 1 5
10 2 3 7