Bookshelves
InterviewTime limit1sMemory limit1024 MB
Given counts of small, medium, and large books and the shelf size, find the fewest shelves needed to hold all books without splitting any book.
- Level
Medium5 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
You are buying bookshelves to fit all of your books. You already know which books you have and need to work out how many shelves are required. The books come in three sizes: a small book takes space unit, a medium book takes , and a large book takes . Each shelf holds a fixed number of space units.
Given how many books of each size you have, write a program that computes the fewest shelves needed to fit all of them.
Input
The first line contains three integers: the number of small books, the number of medium books, and the number of large books, in that order. The number of books of each size is at most .
The next line contains an integer (), the size of one shelf in space units. At least shelves are always required.
Output
Print the minimum number of shelves needed to fit all the books.