루미 알고리즘

#1329골드Ferry Loading

PO 2013 온라인 예선코딩출제 Oskar Werkelin Ahlin영어 원문이 문제가 어렵다면 — 배우는 순서 보기

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

Problem

A ferry is being loaded with cars, and there's a long line of cars queued up to enter the ferry. Since the time between the ferry's departures is very long, it's important that as many cars as possible can board the ferry. The shipping company, Crappy Shippers Inc., has lately recieved a large number of complaints from the organization Angry Young Algorithmicists, stating that the packing of the cars on the ferry is “bad”, “suboptimal”, “heuristical” and “unsustainable”. The CEO of the company, Ernst. I. S. Crappy confirms that they have been sloppy about packing the ferry, and has just made a statement that they will always pack the ferry with as many cars as possible. Ernst said nothing about how they will do this, but there's a rumor floating around that they have requested the assistance of the Swedish Olympiad in Informatics.

The ferry has four lanes, where each lane is a fixed length which is the same for all the lanes. A line of cars are waiting in a queue to board the ferry, and they will board it in their queuing order. The staff of the shipping company can decide what lane a car should enter (if it fits). When a car can't fit in any of the lanes, the ferry is considered full (this means that no car in the queue is ever skipped, even if a later car could fit in some lane). It's also important that there's a one meter safety margin between cars adjacent in the same lane.

Given the length of the ferry and the lengths of the cars in the queue, help the staff compute the maximum number of cars that can board the ferry.

(그림은 원문 저장소에서 볼 수 있습니다)

Figure 1: An example of an optimal packing of the ferry. The ferry is 5 meters long, and the lengths of the cars in the queue are 2, 1, 2, 5, 1, 1, 2, 1, 1, 2, of which only the first 8 could fit the ferry.

Input

The first line contains the integer N (N ≤ 200), the number of cars. The second line contains the integer L (L ≤ 60), the length of the lanes. This is followed by N integers on a line, where each integer is the length of a car in the same order that they're queuing in. Each car is between 1 and 10 meters long, and does not exceed the length of the ferry.

Output

Output a single integer: the maximum number of cars that can board the ferry.

Points

Your solution will be tested on several test case groups. To get the points for a group, it must pass all the test cases in the group.

GroupPoint valueConstraints
140N ≤ 20, L ≤ 40
260No additional constraints.

예제

예제 1

입력
10
5
2 1 2 5 1 1 2 1 1 2
출력
8

예제 2

입력
6
1
1 1 1 1 1 1
출력
4

예제 3

입력
10
10
1 2 7 2 5 9 10 9 4 3
출력
7

출처 표기

출처: Programmeringsolympiaden 2013년 온라인 예선 · 원문 페이지 · 이용 조건 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). 루미 알고리즘은 위 단체들과 관계없는 별도의 서비스이며, 자료는 원문 그대로 싣습니다. 문제마다 출처와 이용 조건을 따로 표기합니다.