NOI Contest Archive

Archive / 2020 / March 2020

Subsets Sum

Medium · National Olympiad in Informatics Sri Lanka - March 2020

You are given a set of N positive integers (set A). Find the number of subsets that have their sums equal to S.
Subsets may have any number of integers between 1 to N (inclusive).
Note: A set will not consist of repeated elements

Example 1

If A = {1, 2, 5, 10, 12} & S = 12,  
Then subsets are,  
{2, 10} & {12}

Example 2

If A = {1, 2, 3, 4, 5} & S = 5,  
Then subsets are,  
{1, 4}, {2, 3} & {5}

Input Format

First line contains 2 integers, N & S.
Next line contains N space seperated integers(integers of the set A), with the ith of them being Ai.

Output Format

Number of subsets that have their sums equal to S.

Constraints

Limits

Sample Input 0

5 12
1 2 5 10 12

Sample Output 0

2

Sample Input 1

5 5
1 2 3 4 5

Sample Output 1

3