#K66727. Maximum Distinct Integers Sum

    ID: 32485 Type: Default 1000ms 256MiB

Maximum Distinct Integers Sum

Maximum Distinct Integers Sum

You are given a list of N integers and an integer S. Your task is to select a subset of distinct integers from the list such that the sum of the chosen integers does not exceed S, and the count of selected integers is maximized.

Note: Each integer in the subset must be unique. The input is read from stdin and the output should be written to stdout.

Input Format:

  • The first line contains two integers N and S separated by a space.
  • The second line contains N space-separated integers.

Output Format:

  • A single integer representing the maximum number of distinct integers that can be selected such that their total sum is less than or equal to S.

The problem can also be mathematically formulated as: $$\max \{ k \mid \exists\, x_1, x_2,\ldots,x_k \text{ distinct with } \sum_{i=1}^{k} x_i \le S \}.$$

inputFormat

The first line of input contains two integers N and S where N is the number of integers in the list and S is the target sum.

The second line contains N integers separated by spaces representing the elements of the list.

outputFormat

Output a single integer which is the maximum number of distinct integers that can be chosen from the list with a total sum less than or equal to S.

## sample
6 15
5 2 3 8 2 3
3