Melons
InterviewTime limit1sMemory limit1024 MB
For each start index x, count the boxes needed to pack melons x through N in order under limit L, and report the weight of the last box.
- Level
Medium6 of 10
- Topics
- Greedy, Prefix sum, Two pointers, Dynamic programming
- Solved
- No attempts yet
Problem
In EGOI Farm, employees receive and ship melons. This morning, melons arrived. The melons are numbered from 1 to , and the weight of melon () is .
Rie works at EGOI Farm, packing melons into boxes. An integer () is decided. Then she receives melons in this order. She packs them by repeating the following process.
- Rie takes an empty box and keeps putting melons into it. If the total weight in the box would exceed after adding the next melon, she does not put that melon in. She then ships the box. In this case, the next melon goes into a new box.
After melon is put into a box, she ships that box, and the job ends.
Rie wants to prepare for every possible value of . Given the melon weights and the maximum box weight , write a program that computes, for every , the number of boxes she ships and the total weight of melons in the last box.
Input
The first line contains and . Each of the next lines contains one value: .
N L
A_1
A_2
\vdots
A_N
Output
Print lines. The -th line contains, for , the number of shipped boxes and the total weight of melons in the last box, separated by a space.
Constraints
- ()
- ()