루미 알고리즘

#1309골드Book Shelves

PO 2012 학교 예선코딩영어 원문이 문제가 어렵다면 — 배우는 순서 보기

영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)

Problem

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 required. The books have three sizes: a small book has width 1, a medium book width 2 and a big book width 3. Each shelf has the same given width.

Given the number of books you have of each kind, write a program to compute the minimum number of shelves needed.

Input

The first line contains three integers that, in order, describe the number of small books, the number of medium books and the number of big books. There will be at most 20 books of each kind.

The second line contains the integer S (S ≤ 20), the width of a single shelf. You will always need at least 2 shelves.

Output

Print the minimum number of shelves that you need to fit all the books.

Scoring

Your solution will be tested on a set of test case groups. To get the points for a group, you need to pass all the test cases in the group.

GroupPoint valueConstraints
166There are at most 25 books, and S ≤ 10.
234No additional constraints.

예제

예제 1

입력
20 0 0
10
출력
2

예제 2

입력
0 0 10
10
출력
4

예제 3

입력
8 7 5
15
출력
3

예제 4

입력
1 4 13
7
출력
8

출처 표기

출처: Programmeringsolympiaden 2012년 학교 예선 · 원문 페이지 · 이용 조건 CC BY-SA · LaTeX 원문을 화면용 글로 옮겼습니다(수식·표의 모양이 다를 수 있습니다). 내용은 고치지 않았습니다.

크리에이티브 커먼즈 저작자표시-동일조건변경허락.

문제 출처: 한국정보올림피아드(KOI) (CC BY-NC-SA 4.0) · International Olympiad in Informatics (IOI) (CC BY) · Centre for Education in Mathematics and Computing (CEMC), University of Waterloo (CC BY-NC 4.0) · Programmeringsolympiaden (CC BY-SA) · CSES Problem Set (Antti Laaksonen) (CC BY-NC-SA 4.0). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.