Protein drinks
Statement
N protein drinks, numbered 1 to N, are lined up in a store. Each protein drink contains at least 1 protein, and the protein content of each drink is at most 1,000. The protein amount of each drink is a natural number between 1 and 1,000.
If you buy a lot of protein drinks, sorting them for recycling takes a lot of time. The goal is therefore to take in enough protein without buying too many drinks. Specifically, you want to buy and drink at most K of them and get at least M protein in total.
There is one more condition. The number of protein drinks you take has to be odd. So write a program that counts every case, that is, every combination, where you drink an odd number of protein drinks, at most K of them, and still get at least M protein.
For example, suppose N=5, K=3, M=20 and the protein amount in each drink is as in the table below.
| Number | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Protein | 3 | 7 | 10 | 20 | 21 |
Taking every possible combination, 12 combinations meet the condition in this example. They are (4), (5), (1, 2, 3), (1, 2, 4), (1, 2, 5), (1, 3, 4), (1, 3, 5), (1, 4, 5), (2, 3, 4), (2, 3, 5), (2, 4, 5), (3, 4, 5), so the total number of cases is 12. See the table below.
| Combination | Protein amount | |
|---|---|---|
| No. 1 | (4) | 20 |
| No. 2 | (5) | 21 |
| No. 3 | (1, 2, 3) | 20 |
| No. 4 | (1, 2, 4) | 30 |
| No. 5 | (1, 2, 5) | 31 |
| No. 6 | (1, 3, 4) | 33 |
| No. 7 | (1, 3, 5) | 34 |
| No. 8 | (1, 4, 5) | 44 |
| No. 9 | (2, 3, 4) | 37 |
| No. 10 | (2, 3, 5) | 38 |
| No. 11 | (2, 4, 5) | 48 |
| No. 12 | (3, 4, 5) | 51 |
So the answer in this example is 12.
Input and Output Examples
Example 1
Input
5, 3, 20, [3, 7, 10, 20, 21]
Output
12
Example 2
Input
7, 5, 200, [55, 78, 70, 72, 62, 91, 37]
Output
39
Input
First the number of protein drinks N is given. N is a natural number less than or equal to 9.
Next comes K, the maximum number of protein drinks you can buy. K is a natural number less than or equal to N.
Next comes M, the amount of protein you have to take in. You have to take in at least M protein, and M is a natural number less than or equal to 10,000.
Next comes arr, an array holding the protein content of each of the N protein drinks in order from number 1 to number N. The amount of protein in each drink is a natural number between 1 and 1,000.
Output
Return the number of cases, that is, combinations, that reach at least M protein when you drink at most K protein drinks and take an odd number of them. Return 0 if no case meets the condition.
Requirements
- You must write a solution(N, K, M, arr) function and return the answer
- Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
- The languages you can use are Python and JavaScript
- The memory limit is 256MB. The browser does not measure it, it only states it
- The time limit is set by measuring the setter's reference solution on the same runtime
- On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
- The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
- There are 18 cases, and 5 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
- You have to pass all 18 cases to solve this.
Examples
5 public cases. Judging also uses hidden cases. You have to pass all 18 cases to solve this.
5, 3, 20, [3, 7, 10, 20, 21]
12
7, 5, 200, [55, 78, 70, 72, 62, 91, 37]
39
1, 1, 601, [436]
0
3, 2, 3401, [867, 70, 899]
0
8, 7, 4658, [763, 297, 876, 709, 574, 797, 667, 32]
1
Notes
Background that helps with solving. The rules you have to follow are in the input and output specs and the requirements above.
This is problem 2 of practice test 9 in the original.
Solution
Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.
Submitting requires you to log in. Running against the public cases works without one.
You can test with 5 public cases. Submitting runs the hidden cases too.
People who solved this problem
Nobody yet. You could be the first.