Roll Cake
InterviewTime limit2sMemory limit512 MB
Given up to M cuts across cakes of length at most 1000, maximise how many length-10 pieces you can cut out of them.
- Level
Medium4 of 10
- Topics
- Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
Today is Jaehyun's birthday. N friends each gave Jaehyun one roll cake as a gift. The lengths of the roll cakes are A1, A2, ..., AN. Jaehyun only eats roll cakes of length 10. So Jaehyun wants to cut the roll cakes to make as many length-10 roll cakes as possible.
A roll cake can be cut by the following process.
- Choose one roll cake to cut. Only a roll cake whose length is greater than 1 can be cut. Let x be the length of the chosen roll cake.
- Choose a natural number y such that 0 < y < x.
- Cut the roll cake into two roll cakes of lengths y and x - y.
Jaehyun can cut the roll cakes at most M times. Write a program that finds the maximum number of length-10 roll cakes Jaehyun can obtain.
Input
The first line gives the number of roll cakes N and the maximum number of cuts M. (1 ≤ N, M ≤ 1,000)
The second line gives the lengths of the roll cakes A1, A2, ..., AN. (1 ≤ Ai ≤ 1,000)
Output
Print the maximum number of length-10 roll cakes Jaehyun can obtain.