OpenKattis
POwarmup23 svår: intro DP

Start

2022-11-10 16:00 CET

POwarmup23 svår: intro DP

End

2022-11-17 16:00 CET
The end is near!
Contest is over.
Not yet started.
Contest is starting in -772 days 12:41:14

Time elapsed

168:00:00

Time remaining

0:00:00

Problem B
Book Shelves

You are going to buy book shelves to put all your books in. You already know how many books you have and need to count the number of book shelves you need. The books have three sizes: a small book takes $1$ width units, a medium book takes $2$ width units and a big book takes $3$ width units. Each shelf can fit a certain number of width units.

Given the number of books you have of each kind, write a program to compute the number of shelves you need if you want to buy as few shelves as possible.

There will be at most $20$ books of each kind.

Input

The first line contains three integers that, in order, describes the number of small books, the number of medium books and the number of big books.

The second line contains the integer $S$, the size of a single shelf. You will always need at least 2 shelves.

Output

Print the minimum number of shelves (all of them with size $S$) that you need to fit all the books.

Grading

Your program will be tested on three test cases. If you pass two of them, you will get $50$ points. If you pass all three of them, you will get $100$ points.

Sample Input 1 Sample Output 1
20 0 0
10
2
Sample Input 2 Sample Output 2
0 0 10
10
4
Sample Input 3 Sample Output 3
8 7 5
15
3
Sample Input 4 Sample Output 4
1 4 13
7
8