Muscle Loss
InterviewTime limit1sMemory limit256 MB
Count orderings of N workout kits (N at most 8) such that a starting total of 500, which drops by K each day, never falls below 500.
- Level
Medium4 of 10
- Topics
- Brute force, Backtracking, Simulation, Implementation
- Solved
- No attempts yet
Problem
A graduate student who loves weight training currently has a total of 500 across the big three lifts. However, the total decreases by K each day. For example, with K=4, after three days the total drops to 488. So if the student does not work out and just rests, the total only goes down every day.
Fortunately, the student has N distinct workout kits. One kit is used per day, and the student may freely choose which kit to use on each day. Each workout kit has its own weight increase, and the total increases immediately each time a kit is used. Some workout kits may have the same weight increase, but they are still treated as distinct kits. Each kit can be used exactly once over the N days.
The student wants to plan the N days of workouts so that the total stays at least 500 throughout the training period. From day 1 through day N, the total must never drop below 500 at any point.
For example, let N=3 and K=4, and suppose the weight increases of the workout kits are as follows.

Suppose the kits are applied in the order 1, 3, 2. On day 1 the total increases by 3, but at the same time it decreases by 4 over the day, so after day 1 the total becomes 499. The condition is not satisfied.
On the other hand, suppose the kits are applied in the order 3, 1, 2. Then from day 1 until the day all workouts are finished, the total stays at least 500 at every point.
Given information about the N workout kits, write a program that outputs the number of ways to use one workout kit per day over N days such that the total stays at least 500 throughout the training period.
In the example above, 4 of all the orderings satisfy the condition.

Input
The first line gives the natural numbers N and K, separated by a space. (1 ≤ N ≤ 8, 1 ≤ K ≤ 50) The second line gives the weight increase A of each workout kit, separated by spaces. (1 ≤ A ≤ 50)
Output
Among all the ways to use the N workout kits over N days, output the number of ways such that the total stays at least 500 throughout the training period.