Ice Hockey World Championship
Time limit1sMemory limit1024 MB
Count the subsets of up to 40 ticket prices whose total is at most M.
- Level
Medium6 of 10
- Topics
- Divide and conquer, Sorting, Binary search
- Solved
- No attempts yet
Problem
This year the Ice Hockey World Championship was held in the Czech Republic. Bobek has arrived in Prague and wants to watch some of the matches. He has no favourite team and no scheduling constraints, so with enough money he could watch every match. His money is a fixed amount of Czech crowns, and he can spend all of it on tickets.
Given the ticket price of each match, count the ways Bobek can choose a set of matches without exceeding his budget. Two ways are different if some match is watched in one of them and not in the other. Watching no match at all counts as one way.
Input
The first line contains the number of matches and the amount of money Bobek can spend . (, )
The second line contains the ticket prices separated by spaces. Each price is an integer between and .
Output
Print the number of ways on one line. Because of the limit on , this value never exceeds .
Hint
When the prices are , , , , and the budget is , the eight ways are:
- watch no match
- the match worth
- the first match worth
- the second match worth
- the match worth and the first match worth
- the match worth and the second match worth
- both matches worth
- the match worth