Problem Statement for mc1p3

**Mock CCC Contest 1 Problem 3 - Greedy For Pies** Ms. Spiliopoulos has seen that the MaCS math class average is at an 89% which makes her very worried. She decides to hold a pie-eating contest for extra credit. There are `N` types of pies available and she gives the class `K` seconds to eat. The sizes of each pie type varies: pie `i` takes `a[i]` seconds to finish. Usually, on math tests, when time is up, Ms. Spiliopoulos would say "finish your last thought", so surely on the pie eating contest she would say "finish your last pie"...right? In other words, "if you had started a pie before I called time, you may finish it". You're not very interested in eating the most pie but instead want to spend the most time as possible eating pie, just to annoy her. What is the maximum amount of time, in seconds, you can spend eating pie, if you eat in an optimal way? (You can eat any type of pie any number of times. In addition, you don't have to eat every type of pie or use the "finish your last pie" rule). **Input Specification:** First line: Two integers: `N` (number of pie types) and `K` (`1 ≤ K ≤ 4000`) (amount of time in seconds before Ms. Spiliopoulos says "Finish your last pie") Second line: `N` space separated integers describing the number of minutes it takes to eat a pie of each type (the array `a`, `1 ≤ a[i] ≤ 4000`) **Output Specification:** One integer: The maximum number of seconds you can spend eating pie. **Subtasks:** For 10% of the marks, `1 ≤ N ≤ 8` For an additional 20%, `1 ≤ N ≤ 200` For full marks: `1 ≤ N ≤ 4000` **Sample input:** ``` 3 10 10 4 5 ``` **Output for sample input:** ``` 19 ``` **Explanation for sample case:** You can eat one type 2 pie and one type 3 pie, taking 9 seconds, so you can start a type 1 pie just a minute before she calls time. Since you had already started it, she will let you finish eating the pie, taking `4 + 5 + 9 = 19` seconds.


🕑 Time limit: 2.5 seconds
 java: 5.0 seconds
 python: 5.0 seconds
⚎ Memory limit: 256.0 MB