#QHD0000052. Xếp xe lên phà (Ferry Loading)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xếp xe lên phà (Ferry Loading)
Ferry Loading
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A ferry has two separate lanes, port and starboard. Each lane can hold cars of total length at most metres. There are cars in a single ordered queue; car is centimetres long.
Cars must be loaded in their given order. A car may be assigned to either lane if there is sufficient remaining room. You may not skip a car in order to load a later car. Maximize the number of cars in the longest loadable prefix, and print any valid assignment of those cars to the two lanes. Notice the difference between metres and centimetres.
Input
The first line contains . The next lines each contain a car length in centimetres.
Output
Print the maximum number of loaded cars, followed by lines in queue order, each port or starboard. Any valid optimal assignment is accepted.
Subtasks
Scoring groups are independent. All constraints listed for a group apply simultaneously.
- Subtask 1 (20%): (metres), , (cm).
- Subtask 2 (30%): (metres), , (cm).
- Subtask 3 (50%): (metres), , (cm).
Examples
Input
5 4
300
200
300
200
Output
4
port
port
starboard
starboard
Explanation
Each lane has capacity cm. Put cars 1 and 2 on port (), and cars 3 and 4 on starboard (), so all four cars fit.